diff --git a/doc/api/assert.md b/doc/api/assert.md index 591d26a515d..9ce918dab94 100644 --- a/doc/api/assert.md +++ b/doc/api/assert.md @@ -326,7 +326,7 @@ rejected. See [`assert.rejects()`][] for more details. When `assert.doesNotReject()` is called, it will immediately call the `block` function, and awaits for completion. -Besides the async nature to await the completion behaves identical to +Besides the async nature to await the completion behaves identically to [`assert.doesNotThrow()`][]. ```js @@ -844,6 +844,48 @@ assert(0); // assert(0) ``` +## assert.rejects(block[, error][, message]) + +* `block` {Function} +* `error` {RegExp|Function|Object} +* `message` {any} + +Awaits for promise returned by function `block` to be rejected. + +When `assert.rejects()` is called, it will immediately call the `block` +function, and awaits for completion. + +Besides the async nature to await the completion behaves identically to +[`assert.throws()`][]. + +If specified, `error` can be a constructor, [`RegExp`][], a validation +function, or an object where each property will be tested for. + +If specified, `message` will be the message provided by the `AssertionError` if +the block fails to reject. + +```js +(async () => { + await assert.rejects( + async () => { + throw new Error('Wrong value'); + }, + Error + ); +})(); +``` + +```js +assert.rejects( + () => Promise.reject(new Error('Wrong value')), + Error +).then(() => { + // ... +}); +``` + ## assert.strictEqual(actual, expected[, message]) -* `block` {Function} -* `error` {RegExp|Function|Object} -* `message` {any} - -Awaits for promise returned by function `block` to be rejected. - -When `assert.rejects()` is called, it will immediately call the `block` -function, and awaits for completion. - -Besides the async nature to await the completion behaves identical to -[`assert.throws()`][]. - -If specified, `error` can be a constructor, [`RegExp`][], a validation -function, or an object where each property will be tested for. - -If specified, `message` will be the message provided by the `AssertionError` if -the block fails to reject. - -```js -(async () => { - await assert.rejects( - async () => { - throw new Error('Wrong value'); - }, - Error - ); -})(); -``` - -```js -assert.rejects( - () => Promise.reject(new Error('Wrong value')), - Error -).then(() => { - // ... -}); -``` - ## assert.throws(block[, error][, message])