Skip to content

Commit 5d6d1fe

Browse files
committed
assert: add warning about assert.doesNotReject
The usefulness of `assert.doesNotReject` is very limited and this warns against the usage. PR-URL: nodejs#19462 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
1 parent 0863a0e commit 5d6d1fe

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

doc/api/assert.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -321,10 +321,16 @@ added: REPLACEME
321321
* `message` {any}
322322

323323
Awaits for the promise returned by function `block` to complete and not be
324-
rejected. See [`assert.rejects()`][] for more details.
324+
rejected.
325+
326+
Please note: Using `assert.doesNotReject()` is actually not useful because there
327+
is little benefit by catching a rejection and then rejecting it again. Instead,
328+
consider adding a comment next to the specific code path that should not reject
329+
and keep error messages as expressive as possible.
325330

326331
When `assert.doesNotReject()` is called, it will immediately call the `block`
327-
function, and awaits for completion.
332+
function, and awaits for completion. See [`assert.rejects()`][] for more
333+
details.
328334

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

0 commit comments

Comments
 (0)