From ab735d01443ec1303ebf15e410d3789a48814e3c Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Thu, 9 Jan 2020 01:14:44 -0600 Subject: [PATCH] doc: update assert.rejects() docs with a validation function example Spawned from my own struggle to use in https://gitlab.com/gitlab-org/gitter/webapp/merge_requests/1702#note_268452483 PR-URL: https://github.com/nodejs/node/pull/31271 Reviewed-By: Anna Henningsen Reviewed-By: Colin Ihrig --- doc/api/assert.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/doc/api/assert.md b/doc/api/assert.md index 5c4a7986ed71d7..8bfe2757821a29 100644 --- a/doc/api/assert.md +++ b/doc/api/assert.md @@ -1111,6 +1111,21 @@ if the `asyncFn` fails to reject. })(); ``` +```js +(async () => { + await assert.rejects( + async () => { + throw new TypeError('Wrong value'); + }, + (err) => { + assert.strictEqual(err.name, 'TypeError'); + assert.strictEqual(err.message, 'Wrong value'); + return true; + } + ); +})(); +``` + ```js assert.rejects( Promise.reject(new Error('Wrong value')),