Skip to content

Commit

Permalink
Update documentation to include information about "toThrowWithMessage"
Browse files Browse the repository at this point in the history
  • Loading branch information
Alcedo Nathaniel De Guzman Jr committed Sep 22, 2018
1 parent 595870b commit ee823b3
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ If you've come here to help contribute - Thanks! Take a look at the [contributin
- Further proposals in [#117](https://github.com/jest-community/jest-extended/issues/117) PRs welcome
- [Function](#function)
- [.toBeFunction()](#tobefunction)
- [.toThrowWithMessage()](#tothrowwithmessagetype-message)
- [Mock](#mock)
- [.toHaveBeenCalledBefore()](#tohavebeencalledbefore)
- [.toHaveBeenCalledAfter()](#tohavebeencalledafter)
Expand Down Expand Up @@ -398,6 +399,29 @@ test('passes when value is a function', () => {
});
```
#### .toThrowWithMessage(type, message)
Use `.toThrowWithMessage` when checking if a callback function throws an error with a given error type and given error message.
```js
test('throws an error of type TypeError with message "hello world"', () => {
expect(() => {
throw TypeError("hello world");
}).toThrowWithMessage(TypeError, "hello world");
expect(() => {
throw TypeError("hello world");
}).toThrowWithMessage(TypeError, /hello world/);

expect(() => {
throw TypeError("hello world 2");
}).not.toThrowWithMessage(TypeError, "hello world");

expect(() => {
throw TypeError("hello world 2");
}).not.toThrowWithMessage(TypeError, /hello world/);
});
```
### Mock
#### .toHaveBeenCalledBefore()
Expand Down

0 comments on commit ee823b3

Please sign in to comment.