Skip to content

Commit abb6321

Browse files
authored
Alias parity for all spy matchers (#5826)
* Add .toBeCalledTimes and .toHaveBeenNthCalledWith * Update CHANGELOG.md
1 parent f31f253 commit abb6321

5 files changed

Lines changed: 822 additions & 568 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,14 @@
2828
* `[jest-mock]` Add tracking of return values in the `mock` property
2929
([#5752](https://github.com/facebook/jest/pull/5752))
3030
* `[jest-mock]` Add tracking of thrown errors in the `mock` property
31-
([5764](https://github.com/facebook/jest/pull/5764))
31+
([#5764](https://github.com/facebook/jest/pull/5764))
3232
* `[expect]`Add nthCalledWith spy matcher
3333
([#5605](https://github.com/facebook/jest/pull/5605))
3434
* `[jest-cli]` Add `isSerial` property that runners can expose to specify that
3535
they can not run in parallel
3636
([#5706](https://github.com/facebook/jest/pull/5706))
37+
* `[expect]` Add `.toBeCalledTimes` and `toHaveBeenNthCalledWith` aliases
38+
([#5826](https://github.com/facebook/jest/pull/5826))
3739
* `[jest-cli]` Interactive Snapshot Mode improvements
3840
([#5864](https://github.com/facebook/jest/pull/5864))
3941

docs/ExpectAPI.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,8 @@ describe('drinkAll', () => {
571571

572572
### `.toHaveBeenCalledTimes(number)`
573573

574+
Also under the alias: `.toBeCalledTimes(number)`
575+
574576
Use `.toHaveBeenCalledTimes` to ensure that a mock function got called exact
575577
number of times.
576578

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

629-
### `.nthCalledWith(nthCall, arg1, arg2, ....)`
631+
### `.toHaveBeenNthCalledWith(nthCall, arg1, arg2, ....)`
632+
633+
Also under the alias: `.nthCalledWith(arg1, arg2, ...)`
630634

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

0 commit comments

Comments
 (0)