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 codebytere committed Mar 15, 2020
1 parent d4501e0 commit ecaf255
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 ecaf255

Please sign in to comment.