Skip to content

Commit 8b69d4a

Browse files
committed
doc: add warning to assert.doesNotThrow()
Using `assert.doesNotThrow()` has no benefit over adding a comment next to some code that should not throw. Therefore it is from now on discouraged to use it. PR-URL: #18699 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
1 parent 4893f70 commit 8b69d4a

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

doc/api/assert.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,11 @@ changes:
330330
Asserts that the function `block` does not throw an error. See
331331
[`assert.throws()`][] for more details.
332332

333+
Please note: Using `assert.doesNotThrow()` is actually not useful because there
334+
is no benefit by catching an error and then rethrowing it. Instead, consider
335+
adding a comment next to the specific code path that should not throw and keep
336+
error messages as expressive as possible.
337+
333338
When `assert.doesNotThrow()` is called, it will immediately call the `block`
334339
function.
335340

0 commit comments

Comments
 (0)