Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@
* `[jest-mock]` Add tracking of return values in the `mock` property
([#5752](https://github.com/facebook/jest/pull/5752))
* `[jest-mock]` Add tracking of thrown errors in the `mock` property
([5764](https://github.com/facebook/jest/pull/5764))
([#5764](https://github.com/facebook/jest/pull/5764))
* `[expect]`Add nthCalledWith spy matcher
([#5605](https://github.com/facebook/jest/pull/5605))
* `[jest-cli]` Add `isSerial` property that runners can expose to specify that
they can not run in parallel
[#5706](https://github.com/facebook/jest/pull/5706)
([#5706](https://github.com/facebook/jest/pull/5706))
* `[expect]` Add `.toBeCalledTimes` and `toHaveBeenNthCalledWith` aliases
([#5826](https://github.com/facebook/jest/pull/5826))

### Fixes

Expand Down
14 changes: 9 additions & 5 deletions docs/ExpectAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,8 @@ describe('drinkAll', () => {

### `.toHaveBeenCalledTimes(number)`

Also under the alias: `.toBeCalledTimes(number)`

Use `.toHaveBeenCalledTimes` to ensure that a mock function got called exact
number of times.

Expand Down Expand Up @@ -626,10 +628,12 @@ test('applying to all flavors does mango last', () => {
});
```

### `.nthCalledWith(nthCall, arg1, arg2, ....)`
### `.toHaveBeenNthCalledWith(nthCall, arg1, arg2, ....)`

Also under the alias: `.nthCalledWith(arg1, arg2, ...)`

If you have a mock function, you can use `.nthCalledWith` to test what arguments
it was nth called with. For example, let's say you have a
If you have a mock function, you can use `.toHaveBeenNthCalledWith` to test what
arguments it was nth called with. For example, let's say you have a
`drinkEach(drink, Array<flavor>)` function that applies `f` to a bunch of
flavors, and you want to ensure that when you call it, the first flavor it
operates on is `'lemon'` and the second one is `'octopus'`. You can write:
Expand All @@ -640,8 +644,8 @@ Note that, nth argument must be positive integer starting from 1.
test('drinkEach drinks each drink', () => {
const drink = jest.fn();
drinkEach(drink, ['lemon', 'octopus']);
expect(drink).nthCalledWith(1, 'lemon');
expect(drink).nthCalledWith(2, 'octopus');
expect(drink).toHaveBeenNthCalledWith(1, 'lemon');
expect(drink).toHaveBeenNthCalledWith(2, 'octopus');
});
```

Expand Down
Loading