From 8e88a180b90d406324f4f6b113ef642ff28fe490 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Sat, 10 Feb 2018 16:50:20 +0100 Subject: [PATCH] doc: add warning to assert.doesNotThrow() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: https://github.com/nodejs/node/pull/18699 Reviewed-By: Matteo Collina Reviewed-By: Luigi Pinca Reviewed-By: James M Snell Reviewed-By: Gibson Fahnestock Reviewed-By: Tiancheng "Timothy" Gu Reviewed-By: Michaƫl Zasso Reviewed-By: Sakthipriyan Vairamani --- doc/api/assert.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/doc/api/assert.md b/doc/api/assert.md index 6eccfa7ee115c3..d9b7fd56829f64 100644 --- a/doc/api/assert.md +++ b/doc/api/assert.md @@ -330,6 +330,11 @@ changes: Asserts that the function `block` does not throw an error. See [`assert.throws()`][] for more details. +Please note: Using `assert.doesNotThrow()` is actually not useful because there +is no benefit by catching an error and then rethrowing it. Instead, consider +adding a comment next to the specific code path that should not throw and keep +error messages as expressive as possible. + When `assert.doesNotThrow()` is called, it will immediately call the `block` function.