Skip to content

Commit cae60ca

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. Backport-PR-URL: #22380 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 e6131c2 commit cae60ca

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
@@ -191,6 +191,11 @@ changes:
191191
Asserts that the function `block` does not throw an error. See
192192
[`assert.throws()`][] for more details.
193193

194+
Please note: Using `assert.doesNotThrow()` is actually not useful because there
195+
is no benefit by catching an error and then rethrowing it. Instead, consider
196+
adding a comment next to the specific code path that should not throw and keep
197+
error messages as expressive as possible.
198+
194199
When `assert.doesNotThrow()` is called, it will immediately call the `block`
195200
function.
196201

0 commit comments

Comments
 (0)