-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
doc: improve assert documentation #22692
Conversation
This fixes the officially accepted message types for `assert.throws()`, `assert.rejects()`, `assert.doesNotThrow()` and `assert.doesNotReject()`. It also renames the `block` argument in those functions to `fn` and `promiseFn` for further clarity.
doc/api/assert.md
Outdated
If specified, `message` will be the message provided by the `AssertionError` if | ||
the block fails to throw. | ||
If specified, `message` will be appended to the message provided by the | ||
`AssertionError` if the fn call fails to throw or in case the error validation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fn
-> `fn`
doc/api/assert.md
Outdated
@@ -408,19 +408,19 @@ parameter is undefined, a default error message is assigned. If the `message` | |||
parameter is an instance of an [`Error`][] then it will be thrown instead of the | |||
`AssertionError`. | |||
|
|||
## assert.doesNotReject(block[, error][, message]) | |||
## assert.doesNotReject(promiseFn[, error][, message]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about asyncFn
? That’s more or less the name the language settled on…
landed in: c1483ba |
This fixes the officially accepted message types for `assert.throws()`, `assert.rejects()`, `assert.doesNotThrow()` and `assert.doesNotReject()`. It also renames the `block` argument in those functions to `fn` and `promiseFn` for further clarity. PR-URL: #22692 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Vse Mozhet Byt <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: George Adams <[email protected]>
The argument names should have been changed in the code as well or else not changed in the docs. > assert.throws('hey', 'jude')
TypeError [ERR_INVALID_ARG_TYPE]: The "block" argument must be of type Function. Received type string
at getActual (assert.js:560:11)
at Function.throws (assert.js:680:24)
> The user doesn't have a way of knowing what the "block" argument is without looking at Node.js source code. They should be able to figure it out by looking at the docs. Before this change, they could. Now they can't. |
This fixes the officially accepted message types for `assert.throws()`, `assert.rejects()`, `assert.doesNotThrow()` and `assert.doesNotReject()`. It also renames the `block` argument in those functions to `fn` and `promiseFn` for further clarity. PR-URL: #22692 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Vse Mozhet Byt <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: George Adams <[email protected]>
This fixes the officially accepted message types for
assert.throws()
,assert.rejects()
,assert.doesNotThrow()
andassert.doesNotReject()
. It also renames theblock
argument inthose functions to
fn
andpromiseFn
for further clarity.Errors would be ambiguous and were never intended to be special
handled as message. They are "accepted" in case it's the third argument
by coercing those to a string.
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes