Skip to content

Commit

Permalink
Update api.assert.md
Browse files Browse the repository at this point in the history
Adding a reference on the idiom of how to assert an async function throws an error: 
lukeed#35 (comment)
  • Loading branch information
nohea authored Dec 2, 2021
1 parent ff50a71 commit 32d14db
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions docs/api.assert.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,18 @@ assert.throws(() => OOPS(), /Cannot read property/);
assert.throws(() => OOPS(), err => err instanceof TypeError);
```

If you are trying to assert an an async function throws an Error, [the following idiom](https://github.com/lukeed/uvu/issues/35#issuecomment-896270152) should be used instead:
```
try {
await asyncFnThatThrows();
assert.unreachable('should have thrown');
} catch (err) {
assert.instance(err, Error);
assert.match(err.message, 'something specific');
assert.is(err.code, 'ERROR123');
}
```

### unreachable(msg?: Message)
Assert that a line should never be reached.

Expand Down

0 comments on commit 32d14db

Please sign in to comment.