Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/api/test.md
Original file line number Diff line number Diff line change
Expand Up @@ -1956,6 +1956,10 @@ changes:
If the number of assertions run in the test does not match the number
specified in the plan, the test will fail.
**Default:** `undefined`.
* `fn` {Function|AsyncFunction} The function under test. If provided, it will take
precedence over the `fn` parameter.
* `name` {string} The name of the test. If provided, it will take precedence over the
`name` parameter.
* `fn` {Function|AsyncFunction} The function under test. The first argument
to this function is a [`TestContext`][] object. If the test uses callbacks,
the callback function is passed as the second argument. **Default:** A no-op
Expand Down
41 changes: 41 additions & 0 deletions test/parallel/test-runner-option-precedence.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
'use strict';
require('../common');
const { test, suite } = require('node:test');

suite('test runner option precedence', () => {
test(
'overridden test name',
{ name: 'options.name overrides test name', plan: 1 },
(t) => {
t.assert.strictEqual(t.name, 'options.name overrides test name');
},
);

test(
'options.fn overrides test function',
{
fn: (t) => {
t.assert.ok(true);
},
plan: 1,
},
(t) => {
t.assert.fail('should not be called');
},
);

test('options.fn only', {
plan: 1,
fn: (t) => {
t.assert.ok(true);
},
});

test({
name: 'single parameter options',
plan: 1,
fn: (t) => {
t.assert.ok(true);
},
});
});
Loading