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 <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
  • Loading branch information
MadLittleMods authored and codebytere committed Feb 27, 2020
1 parent 877ab97 commit 15cc9b0
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions doc/api/assert.md
Original file line number Diff line number Diff line change
Expand Up @@ -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')),
Expand Down

0 comments on commit 15cc9b0

Please sign in to comment.