Skip to content

Commit

Permalink
assert: add warning about assert.doesNotReject
Browse files Browse the repository at this point in the history
The usefulness of `assert.doesNotReject` is very limited and this
warns against the usage.

PR-URL: #19462
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
  • Loading branch information
BridgeAR committed Mar 24, 2018
1 parent 0863a0e commit 5d6d1fe
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions doc/api/assert.md
Expand Up @@ -321,10 +321,16 @@ added: REPLACEME
* `message` {any}

Awaits for the promise returned by function `block` to complete and not be
rejected. See [`assert.rejects()`][] for more details.
rejected.

Please note: Using `assert.doesNotReject()` is actually not useful because there
is little benefit by catching a rejection and then rejecting it again. Instead,
consider adding a comment next to the specific code path that should not reject
and keep error messages as expressive as possible.

When `assert.doesNotReject()` is called, it will immediately call the `block`
function, and awaits for completion.
function, and awaits for completion. See [`assert.rejects()`][] for more
details.

Besides the async nature to await the completion behaves identically to
[`assert.doesNotThrow()`][].
Expand Down

0 comments on commit 5d6d1fe

Please sign in to comment.