Skip to content

Commit 8e88a18

Browse files
BridgeARMylesBorins
authored andcommitted
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 <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Gibson Fahnestock <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]>
1 parent 411f3e0 commit 8e88a18

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

doc/api/assert.md

+5
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)