File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1616 ([ #5670 ] ( https://github.com/facebook/jest/pull/5670 ) )
1717* ` [expect] ` Add inverse matchers (` expect.not.arrayContaining ` , etc.,
1818 [ #5517 ] ( https://github.com/facebook/jest/pull/5517 ) )
19+ * ` [expect] ` Add nthCalledWith spy matcher
20+ ([ #5605 ] ( https://github.com/facebook/jest/pull/5605 ) )
1921* ` [jest-cli] ` Add ` isSerial ` property that runners can expose to specify that
2022 they can not run in parallel
2123 [ #5706 ] ( https://github.com/facebook/jest/pull/5706 )
Original file line number Diff line number Diff line change @@ -622,6 +622,25 @@ test('applying to all flavors does mango last', () => {
622622});
623623```
624624
625+ ### ` .nthCalledWith(nthCall, arg1, arg2, ....) `
626+
627+ If you have a mock function, you can use ` .nthCalledWith ` to test what arguments
628+ it was nth called with. For example, let's say you have a
629+ ` drinkEach(drink, Array<flavor>) ` function that applies ` f ` to a bunch of
630+ flavors, and you want to ensure that when you call it, the first flavor it
631+ operates on is ` 'lemon' ` and the second one is ` 'octopus' ` . You can write:
632+
633+ Note that, nth argument must be positive integer starting from 1.
634+
635+ ``` js
636+ test (' drinkEach drinks each drink' , () => {
637+ const drink = jest .fn ();
638+ drinkEach (drink, [' lemon' , ' octopus' ]);
639+ expect (drink).nthCalledWith (1 , ' lemon' );
640+ expect (drink).nthCalledWith (2 , ' octopus' );
641+ });
642+ ```
643+
625644### ` .toBeCloseTo(number, numDigits) `
626645
627646Using exact equality with floating point numbers is a bad idea. Rounding means
You can’t perform that action at this time.
0 commit comments