@@ -312,6 +312,43 @@ parameter is undefined, a default error message is assigned. If the `message`
312312parameter is an instance of an [ ` Error ` ] [ ] then it will be thrown instead of the
313313` AssertionError ` .
314314
315+ ## assert.doesNotReject(block[ , error] [ , message ] )
316+ <!-- YAML
317+ added: REPLACEME
318+ -->
319+ * ` block ` {Function}
320+ * ` error ` {RegExp|Function}
321+ * ` message ` {any}
322+
323+ Awaits for the promise returned by function ` block ` to complete and not be
324+ rejected. See [ ` assert.rejects() ` ] [ ] for more details.
325+
326+ When ` assert.doesNotReject() ` is called, it will immediately call the ` block `
327+ function, and awaits for completion.
328+
329+ Besides the async nature to await the completion behaves identically to
330+ [ ` assert.doesNotThrow() ` ] [ ] .
331+
332+ ``` js
333+ (async () => {
334+ await assert .doesNotReject (
335+ async () => {
336+ throw new TypeError (' Wrong value' );
337+ },
338+ SyntaxError
339+ );
340+ })();
341+ ```
342+
343+ ``` js
344+ assert .doesNotReject (
345+ () => Promise .reject (new TypeError (' Wrong value' )),
346+ SyntaxError
347+ ).then (() => {
348+ // ...
349+ });
350+ ```
351+
315352## assert.doesNotThrow(block[ , error] [ , message ] )
316353<!-- YAML
317354added: v0.1.21
@@ -330,6 +367,11 @@ changes:
330367Asserts that the function ` block ` does not throw an error. See
331368[ ` assert.throws() ` ] [ ] for more details.
332369
370+ Please note: Using ` assert.doesNotThrow() ` is actually not useful because there
371+ is no benefit by catching an error and then rethrowing it. Instead, consider
372+ adding a comment next to the specific code path that should not throw and keep
373+ error messages as expressive as possible.
374+
333375When ` assert.doesNotThrow() ` is called, it will immediately call the ` block `
334376function.
335377
@@ -802,6 +844,48 @@ assert(0);
802844// assert(0)
803845```
804846
847+ ## assert.rejects(block[ , error] [ , message ] )
848+ <!-- YAML
849+ added: REPLACEME
850+ -->
851+ * ` block ` {Function}
852+ * ` error ` {RegExp|Function|Object}
853+ * ` message ` {any}
854+
855+ Awaits for promise returned by function ` block ` to be rejected.
856+
857+ When ` assert.rejects() ` is called, it will immediately call the ` block `
858+ function, and awaits for completion.
859+
860+ Besides the async nature to await the completion behaves identically to
861+ [ ` assert.throws() ` ] [ ] .
862+
863+ If specified, ` error ` can be a constructor, [ ` RegExp ` ] [ ] , a validation
864+ function, or an object where each property will be tested for.
865+
866+ If specified, ` message ` will be the message provided by the ` AssertionError ` if
867+ the block fails to reject.
868+
869+ ``` js
870+ (async () => {
871+ await assert .rejects (
872+ async () => {
873+ throw new Error (' Wrong value' );
874+ },
875+ Error
876+ );
877+ })();
878+ ```
879+
880+ ``` js
881+ assert .rejects (
882+ () => Promise .reject (new Error (' Wrong value' )),
883+ Error
884+ ).then (() => {
885+ // ...
886+ });
887+ ```
888+
805889## assert.strictEqual(actual, expected[ , message] )
806890<!-- YAML
807891added: v0.1.21
@@ -967,9 +1051,11 @@ second argument. This might lead to difficult-to-spot errors.
9671051[ `WeakSet` ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet
9681052[ `assert.deepEqual()` ] : #assert_assert_deepequal_actual_expected_message
9691053[ `assert.deepStrictEqual()` ] : #assert_assert_deepstrictequal_actual_expected_message
1054+ [ `assert.doesNotThrow()` ] : #assert_assert_doesnotthrow_block_error_message
9701055[ `assert.notDeepStrictEqual()` ] : #assert_assert_notdeepstrictequal_actual_expected_message
9711056[ `assert.notStrictEqual()` ] : #assert_assert_notstrictequal_actual_expected_message
9721057[ `assert.ok()` ] : #assert_assert_ok_value_message
1058+ [ `assert.rejects()` ] : #assert_assert_rejects_block_error_message
9731059[ `assert.strictEqual()` ] : #assert_assert_strictequal_actual_expected_message
9741060[ `assert.throws()` ] : #assert_assert_throws_block_error_message
9751061[ `strict mode` ] : #assert_strict_mode
0 commit comments