GeezerVison is showing github.com — doc: formalize fn/name as part of TestOptions API · nodejs/node@63fbd59
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: doc/api/test.md +4Lines changed: 4 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -1954,6 +1954,10 @@ changes: |
1954 | 1954 | If the number of assertions run in the test does not match the number |
1955 | 1955 | specified in the plan, the test will fail. |
1956 | 1956 | **Default:** `undefined`. |
| 1957 | + * `fn` {Function|AsyncFunction} The function under test. If provided, it will take |
| 1958 | + precedence over the `fn` parameter. |
| 1959 | + * `name` {string} The name of the test. If provided, it will take precedence over the |
| 1960 | + `name` parameter. |
1957 | 1961 | * `fn` {Function|AsyncFunction} The function under test. The first argument |
1958 | 1962 | to this function is a [`TestContext`][] object. If the test uses callbacks, |
1959 | 1963 | the callback function is passed as the second argument. **Default:** A no-op |
|
Collapse file
Copy file name to clipboard +41Lines changed: 41 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +'use strict'; |
| 2 | +require('../common'); |
| 3 | +const { test, suite } = require('node:test'); |
| 4 | + |
| 5 | +suite('test runner option precedence', () => { |
| 6 | + test( |
| 7 | + 'overridden test name', |
| 8 | + { name: 'options.name overrides test name', plan: 1 }, |
| 9 | + (t) => { |
| 10 | + t.assert.strictEqual(t.name, 'options.name overrides test name'); |
| 11 | + }, |
| 12 | + ); |
| 13 | + |
| 14 | + test( |
| 15 | + 'options.fn overrides test function', |
| 16 | + { |
| 17 | + fn: (t) => { |
| 18 | + t.assert.ok(true); |
| 19 | + }, |
| 20 | + plan: 1, |
| 21 | + }, |
| 22 | + (t) => { |
| 23 | + t.assert.fail('should not be called'); |
| 24 | + }, |
| 25 | + ); |
| 26 | + |
| 27 | + test('options.fn only', { |
| 28 | + plan: 1, |
| 29 | + fn: (t) => { |
| 30 | + t.assert.ok(true); |
| 31 | + }, |
| 32 | + }); |
| 33 | + |
| 34 | + test({ |
| 35 | + name: 'single parameter options', |
| 36 | + plan: 1, |
| 37 | + fn: (t) => { |
| 38 | + t.assert.ok(true); |
| 39 | + }, |
| 40 | + }); |
| 41 | +}); |