Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wrong messages for nthCalledWith #6340

Merged
merged 5 commits into from
May 30, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
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