Skip to content

Commit

Permalink
docs: update readme, split async test
Browse files Browse the repository at this point in the history
Application of feedback
#315 (comment)
  • Loading branch information
GerkinDev committed Jun 28, 2021
1 parent a765596 commit a05d5ce
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ test('passes when value is a function', () => {
Use `.toThrowWithMessage` when checking if a callback function throws an error with a given error type and given error message. Message can either be a `String` or a `RegExp`.

```js
test('throws an error of type TypeError with message "hello world"', async () => {
test('throws an error of type TypeError with message "hello world"', () => {
expect(() => {
throw TypeError("hello world");
}).toThrowWithMessage(TypeError, "hello world");
Expand All @@ -458,6 +458,14 @@ test('throws an error of type TypeError with message "hello world"', async () =>
});
```
This works for promise rejections too.
```js
test('throws an error of type TypeError with message "hello world"', async () => {
await expect(Promise.reject(new TypeError("hello world async")).rejects.toThrowWithMessage(TypeError, /hello world/);
});
```
### Mock
#### .toHaveBeenCalledBefore()
Expand Down

0 comments on commit a05d5ce

Please sign in to comment.