Skip to content

Commit

Permalink
Fix wrong messages for nthCalledWith (#6340)
Browse files Browse the repository at this point in the history
* Fix wrong messages for nthCalledWith

* Update the test snapshot

* Add changes to CHANGELOG.md

* Update PR number
  • Loading branch information
chinesedfan authored and cpojer committed May 30, 2018
1 parent c92f39b commit 9035b15
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

### Fixes

* `[expect]` toHaveBeenNthCalledWith/nthCalledWith gives wrong call messages if not matched ([#6340](https://github.com/facebook/jest/pull/6340))
* `[jest-each]` Make sure invalid arguments to `each` points back to the user's code ([#6347](https://github.com/facebook/jest/pull/6347))
* `[expect]` toMatchObject throws TypeError when a source property is null ([#6313](https://github.com/facebook/jest/pull/6313))
* `[jest-cli]` Normalize slashes in paths in CLI output on Windows ([#6310](https://github.com/facebook/jest/pull/6310))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,9 @@ exports[`nthCalledWith should replace 1st, 2nd, 3rd with first, second, third 1`
"<dim>expect(</><red>jest.fn()</><dim>).nthCalledWith(</><green>expected</><dim>)</>

Expected mock function first call to have been called with:
"
<green>\\"foo\\"</>
as argument 1, but it was called with
<red>\\"foo1\\"</>."
`;

exports[`nthCalledWith should replace 1st, 2nd, 3rd with first, second, third 2`] = `
Expand Down Expand Up @@ -1290,7 +1292,9 @@ exports[`toHaveBeenNthCalledWith should replace 1st, 2nd, 3rd with first, second
"<dim>expect(</><red>jest.fn()</><dim>).toHaveBeenNthCalledWith(</><green>expected</><dim>)</>

Expected mock function first call to have been called with:
"
<green>\\"foo\\"</>
as argument 1, but it was called with
<red>\\"foo1\\"</>."
`;

exports[`toHaveBeenNthCalledWith should replace 1st, 2nd, 3rd with first, second, third 2`] = `
Expand Down
6 changes: 5 additions & 1 deletion packages/expect/src/spy_matchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,11 @@ const createNthCalledWithMatcher = (matcherName: string) => (
`Expected ${identifier} ${nthToString(
nth,
)} call to have been called with:\n` +
formatMismatchedCalls(calls, expected, LAST_CALL_PRINT_LIMIT);
formatMismatchedCalls(
calls[nth - 1] ? [calls[nth - 1]] : [],
expected,
LAST_CALL_PRINT_LIMIT,
);

return {message, pass};
};
Expand Down

0 comments on commit 9035b15

Please sign in to comment.