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

Improve output format for mismatchedArgs in mock/spy calls #5846

Merged
merged 1 commit into from
Mar 22, 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

### Features

* `[expect]` Improve output format for mismatchedArgs in mock/spy calls.
([#5846](https://github.com/facebook/jest/pull/5846))
* `[jest-cli]` Add support for using `--coverage` in combination with watch
mode, `--onlyChanged`, `--findRelatedTests` and more
([#5601](https://github.com/facebook/jest/pull/5601))
Expand Down
224 changes: 192 additions & 32 deletions packages/expect/src/__tests__/__snapshots__/spy_matchers.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,21 @@ exports[`lastCalledWith works with Map 2`] = `
"<dim>expect(</><red>jest.fn()</><dim>).lastCalledWith(</><green>expected</><dim>)</>

Expected mock function to have been last called with:
<green>Map {\\"a\\" => \\"b\\", \\"b\\" => \\"a\\"}</> as argument 1, but it was called with <red>Map {1 => 2, 2 => 1}</>."
<green>Map {\\"a\\" => \\"b\\", \\"b\\" => \\"a\\"}</>
as argument 1, but it was called with
<red>Map {1 => 2, 2 => 1}</>.

Difference:

<green>- Expected</>
<red>+ Received</>

<dim> Map {</>
<green>- \\"a\\" => \\"b\\",</>
<green>- \\"b\\" => \\"a\\",</>
<red>+ 1 => 2,</>
<red>+ 2 => 1,</>
<dim> }</>"
`;

exports[`lastCalledWith works with Set 1`] = `
Expand All @@ -48,14 +62,30 @@ exports[`lastCalledWith works with Set 2`] = `
"<dim>expect(</><red>jest.fn()</><dim>).lastCalledWith(</><green>expected</><dim>)</>

Expected mock function to have been last called with:
<green>Set {3, 4}</> as argument 1, but it was called with <red>Set {1, 2}</>."
<green>Set {3, 4}</>
as argument 1, but it was called with
<red>Set {1, 2}</>.

Difference:

<green>- Expected</>
<red>+ Received</>

<dim> Set {</>
<green>- 3,</>
<green>- 4,</>
<red>+ 1,</>
<red>+ 2,</>
<dim> }</>"
`;

exports[`lastCalledWith works with arguments that don't match 1`] = `
"<dim>expect(</><red>jest.fn()</><dim>).lastCalledWith(</><green>expected</><dim>)</>

Expected mock function to have been last called with:
<green>\\"bar\\"</> as argument 2, but it was called with <red>\\"bar1\\"</>."
<green>\\"bar\\"</>
as argument 2, but it was called with
<red>\\"bar1\\"</>."
`;

exports[`lastCalledWith works with arguments that match 1`] = `
Expand Down Expand Up @@ -97,28 +127,36 @@ exports[`lastCalledWith works with many arguments that don't match 1`] = `
"<dim>expect(</><red>jest.fn()</><dim>).lastCalledWith(</><green>expected</><dim>)</>

Expected mock function to have been last called with:
<green>\\"bar\\"</> as argument 2, but it was called with <red>\\"bar3\\"</>."
<green>\\"bar\\"</>
as argument 2, but it was called with
<red>\\"bar3\\"</>."
`;

exports[`lastCalledWith works with many arguments that don't match 2`] = `
"<dim>expect(</><red>jest.fn()</><dim>).lastCalledWith(</><green>expected</><dim>)</>

Expected mock function to have been last called with:
<green>\\"bar\\"</> as argument 2, but it was called with <red>\\"bar3\\"</>."
<green>\\"bar\\"</>
as argument 2, but it was called with
<red>\\"bar3\\"</>."
`;

exports[`lastCalledWith works with many arguments that don't match 3`] = `
"<dim>expect(</><red>jest.fn()</><dim>).lastCalledWith(</><green>expected</><dim>)</>

Expected mock function to have been last called with:
<green>\\"bar\\"</> as argument 2, but it was called with <red>\\"bar3\\"</>."
<green>\\"bar\\"</>
as argument 2, but it was called with
<red>\\"bar3\\"</>."
`;

exports[`lastCalledWith works with many arguments that don't match 4`] = `
"<dim>expect(</><red>jest.fn()</><dim>).lastCalledWith(</><green>expected</><dim>)</>

Expected mock function to have been last called with:
<green>\\"bar\\"</> as argument 2, but it was called with <red>\\"bar3\\"</>."
<green>\\"bar\\"</>
as argument 2, but it was called with
<red>\\"bar3\\"</>."
`;

exports[`lastCalledWith works with trailing undefined arguments 1`] = `
Expand Down Expand Up @@ -254,7 +292,21 @@ exports[`nthCalledWith works with Map 2`] = `
"<dim>expect(</><red>jest.fn()</><dim>).nthCalledWith(</><green>expected</><dim>)</>

Expected mock function first call to have been called with:
<green>Map {\\"a\\" => \\"b\\", \\"b\\" => \\"a\\"}</> as argument 1, but it was called with <red>Map {1 => 2, 2 => 1}</>."
<green>Map {\\"a\\" => \\"b\\", \\"b\\" => \\"a\\"}</>
as argument 1, but it was called with
<red>Map {1 => 2, 2 => 1}</>.

Difference:

<green>- Expected</>
<red>+ Received</>

<dim> Map {</>
<green>- \\"a\\" => \\"b\\",</>
<green>- \\"b\\" => \\"a\\",</>
<red>+ 1 => 2,</>
<red>+ 2 => 1,</>
<dim> }</>"
`;

exports[`nthCalledWith works with Set 1`] = `
Expand All @@ -268,14 +320,30 @@ exports[`nthCalledWith works with Set 2`] = `
"<dim>expect(</><red>jest.fn()</><dim>).nthCalledWith(</><green>expected</><dim>)</>

Expected mock function first call to have been called with:
<green>Set {3, 4}</> as argument 1, but it was called with <red>Set {1, 2}</>."
<green>Set {3, 4}</>
as argument 1, but it was called with
<red>Set {1, 2}</>.

Difference:

<green>- Expected</>
<red>+ Received</>

<dim> Set {</>
<green>- 3,</>
<green>- 4,</>
<red>+ 1,</>
<red>+ 2,</>
<dim> }</>"
`;

exports[`nthCalledWith works with arguments that don't match 1`] = `
"<dim>expect(</><red>jest.fn()</><dim>).nthCalledWith(</><green>expected</><dim>)</>

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

exports[`nthCalledWith works with arguments that match 1`] = `
Expand Down Expand Up @@ -466,7 +534,21 @@ exports[`toHaveBeenCalledWith works with Map 2`] = `
"<dim>expect(</><red>jest.fn()</><dim>).toHaveBeenCalledWith(</><green>expected</><dim>)</>

Expected mock function to have been called with:
<green>Map {\\"a\\" => \\"b\\", \\"b\\" => \\"a\\"}</> as argument 1, but it was called with <red>Map {1 => 2, 2 => 1}</>."
<green>Map {\\"a\\" => \\"b\\", \\"b\\" => \\"a\\"}</>
as argument 1, but it was called with
<red>Map {1 => 2, 2 => 1}</>.

Difference:

<green>- Expected</>
<red>+ Received</>

<dim> Map {</>
<green>- \\"a\\" => \\"b\\",</>
<green>- \\"b\\" => \\"a\\",</>
<red>+ 1 => 2,</>
<red>+ 2 => 1,</>
<dim> }</>"
`;

exports[`toHaveBeenCalledWith works with Set 1`] = `
Expand All @@ -480,14 +562,30 @@ exports[`toHaveBeenCalledWith works with Set 2`] = `
"<dim>expect(</><red>jest.fn()</><dim>).toHaveBeenCalledWith(</><green>expected</><dim>)</>

Expected mock function to have been called with:
<green>Set {3, 4}</> as argument 1, but it was called with <red>Set {1, 2}</>."
<green>Set {3, 4}</>
as argument 1, but it was called with
<red>Set {1, 2}</>.

Difference:

<green>- Expected</>
<red>+ Received</>

<dim> Set {</>
<green>- 3,</>
<green>- 4,</>
<red>+ 1,</>
<red>+ 2,</>
<dim> }</>"
`;

exports[`toHaveBeenCalledWith works with arguments that don't match 1`] = `
"<dim>expect(</><red>jest.fn()</><dim>).toHaveBeenCalledWith(</><green>expected</><dim>)</>

Expected mock function to have been called with:
<green>\\"bar\\"</> as argument 2, but it was called with <red>\\"bar1\\"</>."
<green>\\"bar\\"</>
as argument 2, but it was called with
<red>\\"bar1\\"</>."
`;

exports[`toHaveBeenCalledWith works with arguments that match 1`] = `
Expand Down Expand Up @@ -529,44 +627,68 @@ exports[`toHaveBeenCalledWith works with many arguments that don't match 1`] = `
"<dim>expect(</><red>jest.fn()</><dim>).toHaveBeenCalledWith(</><green>expected</><dim>)</>

Expected mock function to have been called with:
<green>\\"bar\\"</> as argument 2, but it was called with <red>\\"bar3\\"</>.
<green>\\"bar\\"</>
as argument 2, but it was called with
<red>\\"bar3\\"</>.

<green>\\"bar\\"</> as argument 2, but it was called with <red>\\"bar2\\"</>.
<green>\\"bar\\"</>
as argument 2, but it was called with
<red>\\"bar2\\"</>.

<green>\\"bar\\"</> as argument 2, but it was called with <red>\\"bar1\\"</>."
<green>\\"bar\\"</>
as argument 2, but it was called with
<red>\\"bar1\\"</>."
`;

exports[`toHaveBeenCalledWith works with many arguments that don't match 2`] = `
"<dim>expect(</><red>jest.fn()</><dim>).toHaveBeenCalledWith(</><green>expected</><dim>)</>

Expected mock function to have been called with:
<green>\\"bar\\"</> as argument 2, but it was called with <red>\\"bar3\\"</>.
<green>\\"bar\\"</>
as argument 2, but it was called with
<red>\\"bar3\\"</>.

<green>\\"bar\\"</> as argument 2, but it was called with <red>\\"bar2\\"</>.
<green>\\"bar\\"</>
as argument 2, but it was called with
<red>\\"bar2\\"</>.

<green>\\"bar\\"</> as argument 2, but it was called with <red>\\"bar1\\"</>."
<green>\\"bar\\"</>
as argument 2, but it was called with
<red>\\"bar1\\"</>."
`;

exports[`toHaveBeenCalledWith works with many arguments that don't match 3`] = `
"<dim>expect(</><red>jest.fn()</><dim>).toHaveBeenCalledWith(</><green>expected</><dim>)</>

Expected mock function to have been called with:
<green>\\"bar\\"</> as argument 2, but it was called with <red>\\"bar3\\"</>.
<green>\\"bar\\"</>
as argument 2, but it was called with
<red>\\"bar3\\"</>.

<green>\\"bar\\"</> as argument 2, but it was called with <red>\\"bar2\\"</>.
<green>\\"bar\\"</>
as argument 2, but it was called with
<red>\\"bar2\\"</>.

<green>\\"bar\\"</> as argument 2, but it was called with <red>\\"bar1\\"</>."
<green>\\"bar\\"</>
as argument 2, but it was called with
<red>\\"bar1\\"</>."
`;

exports[`toHaveBeenCalledWith works with many arguments that don't match 4`] = `
"<dim>expect(</><red>jest.fn()</><dim>).toHaveBeenCalledWith(</><green>expected</><dim>)</>

Expected mock function to have been called with:
<green>\\"bar\\"</> as argument 2, but it was called with <red>\\"bar3\\"</>.
<green>\\"bar\\"</>
as argument 2, but it was called with
<red>\\"bar3\\"</>.

<green>\\"bar\\"</> as argument 2, but it was called with <red>\\"bar2\\"</>.
<green>\\"bar\\"</>
as argument 2, but it was called with
<red>\\"bar2\\"</>.

<green>\\"bar\\"</> as argument 2, but it was called with <red>\\"bar1\\"</>."
<green>\\"bar\\"</>
as argument 2, but it was called with
<red>\\"bar1\\"</>."
`;

exports[`toHaveBeenCalledWith works with trailing undefined arguments 1`] = `
Expand Down Expand Up @@ -610,7 +732,21 @@ exports[`toHaveBeenLastCalledWith works with Map 2`] = `
"<dim>expect(</><red>jest.fn()</><dim>).toHaveBeenLastCalledWith(</><green>expected</><dim>)</>

Expected mock function to have been last called with:
<green>Map {\\"a\\" => \\"b\\", \\"b\\" => \\"a\\"}</> as argument 1, but it was called with <red>Map {1 => 2, 2 => 1}</>."
<green>Map {\\"a\\" => \\"b\\", \\"b\\" => \\"a\\"}</>
as argument 1, but it was called with
<red>Map {1 => 2, 2 => 1}</>.

Difference:

<green>- Expected</>
<red>+ Received</>

<dim> Map {</>
<green>- \\"a\\" => \\"b\\",</>
<green>- \\"b\\" => \\"a\\",</>
<red>+ 1 => 2,</>
<red>+ 2 => 1,</>
<dim> }</>"
`;

exports[`toHaveBeenLastCalledWith works with Set 1`] = `
Expand All @@ -624,14 +760,30 @@ exports[`toHaveBeenLastCalledWith works with Set 2`] = `
"<dim>expect(</><red>jest.fn()</><dim>).toHaveBeenLastCalledWith(</><green>expected</><dim>)</>

Expected mock function to have been last called with:
<green>Set {3, 4}</> as argument 1, but it was called with <red>Set {1, 2}</>."
<green>Set {3, 4}</>
as argument 1, but it was called with
<red>Set {1, 2}</>.

Difference:

<green>- Expected</>
<red>+ Received</>

<dim> Set {</>
<green>- 3,</>
<green>- 4,</>
<red>+ 1,</>
<red>+ 2,</>
<dim> }</>"
`;

exports[`toHaveBeenLastCalledWith works with arguments that don't match 1`] = `
"<dim>expect(</><red>jest.fn()</><dim>).toHaveBeenLastCalledWith(</><green>expected</><dim>)</>

Expected mock function to have been last called with:
<green>\\"bar\\"</> as argument 2, but it was called with <red>\\"bar1\\"</>."
<green>\\"bar\\"</>
as argument 2, but it was called with
<red>\\"bar1\\"</>."
`;

exports[`toHaveBeenLastCalledWith works with arguments that match 1`] = `
Expand Down Expand Up @@ -673,28 +825,36 @@ exports[`toHaveBeenLastCalledWith works with many arguments that don't match 1`]
"<dim>expect(</><red>jest.fn()</><dim>).toHaveBeenLastCalledWith(</><green>expected</><dim>)</>

Expected mock function to have been last called with:
<green>\\"bar\\"</> as argument 2, but it was called with <red>\\"bar3\\"</>."
<green>\\"bar\\"</>
as argument 2, but it was called with
<red>\\"bar3\\"</>."
`;

exports[`toHaveBeenLastCalledWith works with many arguments that don't match 2`] = `
"<dim>expect(</><red>jest.fn()</><dim>).toHaveBeenLastCalledWith(</><green>expected</><dim>)</>

Expected mock function to have been last called with:
<green>\\"bar\\"</> as argument 2, but it was called with <red>\\"bar3\\"</>."
<green>\\"bar\\"</>
as argument 2, but it was called with
<red>\\"bar3\\"</>."
`;

exports[`toHaveBeenLastCalledWith works with many arguments that don't match 3`] = `
"<dim>expect(</><red>jest.fn()</><dim>).toHaveBeenLastCalledWith(</><green>expected</><dim>)</>

Expected mock function to have been last called with:
<green>\\"bar\\"</> as argument 2, but it was called with <red>\\"bar3\\"</>."
<green>\\"bar\\"</>
as argument 2, but it was called with
<red>\\"bar3\\"</>."
`;

exports[`toHaveBeenLastCalledWith works with many arguments that don't match 4`] = `
"<dim>expect(</><red>jest.fn()</><dim>).toHaveBeenLastCalledWith(</><green>expected</><dim>)</>

Expected mock function to have been last called with:
<green>\\"bar\\"</> as argument 2, but it was called with <red>\\"bar3\\"</>."
<green>\\"bar\\"</>
as argument 2, but it was called with
<red>\\"bar3\\"</>."
`;

exports[`toHaveBeenLastCalledWith works with trailing undefined arguments 1`] = `
Expand Down
Loading