Commit 431fddf
doc: formalize fn/name as part of TestOptions API
`TestOptions` as provided to `node:test`'s `test`/`it` supports both
`name` and `fn` as options per its implementation.
I'd like to formalize this as part of the public, documented API.
### Motivation
I have a use-case for consuming both fields. I'd like to be able to
return the result of a function to `test`/`it` without needing to spread
the parameters; e.g.:
```js
const testOptionsFactory = (opts = {}) => {
return {
fn: () => { /* .. */ },
name: opts.name
};
};
test(testOptionsFactory({name: 'foo'}));
```
If I cannot rely on this behavior, then I would need to instead return
an array of parameters and spread them:
```js
const testParamsFactory = (opts = {}) => {
return opts.name !== undefined
? [opts.name, () => { /* .. */ }] : [() => { /* .. */ }];
};
test(...testParamsFactory({name: 'foo'}));
```
I don't think it's too terribly controversial that the former is more
ergonomic than the latter.
### Next Steps
Once this lands, I plan to propose the addition of these fields to
`@types/node`. Since the fields are not currently publicly documented, I
can't justify such a change.
Signed-off-by: Christopher Hiller <boneskull@boneskull.com>
PR-URL: #64946
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruy Adorno <ruy@vlt.sh>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>1 parent 2c4bf72 commit 431fddf
2 files changed
Lines changed: 45 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1954 | 1954 | | |
1955 | 1955 | | |
1956 | 1956 | | |
| 1957 | + | |
| 1958 | + | |
| 1959 | + | |
| 1960 | + | |
1957 | 1961 | | |
1958 | 1962 | | |
1959 | 1963 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
0 commit comments