Skip to content

Commit

Permalink
doc: update assert.rejects() docs with a validation function example
Browse files Browse the repository at this point in the history
Spawned from my own struggle to use in https://gitlab.com/gitlab-org/gitter/webapp/merge_requests/1702#note_268452483

PR-URL: #31271
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information
MadLittleMods authored and Trott committed Feb 24, 2020
1 parent db28739 commit be2f3a3
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions doc/api/assert.md
Expand Up @@ -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')),
Expand Down

0 comments on commit be2f3a3

Please sign in to comment.