From be2f3a3bf88fd728799d1917f7d82428f53183f0 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 bb9df480ddf5e6..732b4ba8e02d97 100644 --- a/doc/api/assert.md +++ b/doc/api/assert.md @@ -1134,6 +1134,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')),