doc: formalize fn/name as part of TestOptions API · nodejs/node@63fbd59 · GitHub
Skip to content

Commit 63fbd59

Browse files
boneskulladuh95
authored andcommitted
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 07d7cb7 commit 63fbd59

2 files changed

Lines changed: 45 additions & 0 deletions

File tree

doc/api/test.md

Lines changed: 4 additions & 0 deletions
Lines changed: 41 additions & 0 deletions

0 commit comments

Comments
 (0)