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: show correct diff in "toHaveBeenCalledWith" #3289

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/expect/src/jest-expect.ts
Expand Up @@ -356,7 +356,7 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
msg += c().gray(`\n\nReceived: \n${spy.mock.calls.map((callArg, i) => {
let methodCall = c().bold(` ${ordinalOf(i + 1)} ${spy.getMockName()} call:\n\n`)
if (actualCall)
methodCall += diff(callArg, actualCall, { showLegend: false })
methodCall += diff(actualCall, callArg, { showLegend: false })
else
methodCall += stringify(callArg).split('\n').map(line => ` ${line}`).join('\n')

Expand All @@ -370,7 +370,7 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
msg += c().gray(`\n\nReceived: \n${spy.mock.results.map((callReturn, i) => {
let methodCall = c().bold(` ${ordinalOf(i + 1)} ${spy.getMockName()} call return:\n\n`)
if (actualReturn)
methodCall += diff(callReturn.value, actualReturn, { showLegend: false })
methodCall += diff(actualReturn, callReturn.value, { showLegend: false })
else
methodCall += stringify(callReturn).split('\n').map(line => ` ${line}`).join('\n')

Expand Down
28 changes: 14 additions & 14 deletions test/core/test/__snapshots__/mocked.test.ts.snap
Expand Up @@ -6,8 +6,8 @@ exports[`mocked function which fails on toReturnWith > just one call 1`] = `
Received:
1st spy call return:

- 1
+ 2
- 2
+ 1


Number of calls: 1
Expand All @@ -20,18 +20,18 @@ exports[`mocked function which fails on toReturnWith > multi calls 1`] = `
Received:
1st spy call return:

- 1
+ 2
- 2
+ 1

2nd spy call return:

- 1
+ 2
- 2
+ 1

3rd spy call return:

- 1
+ 2
- 2
+ 1


Number of calls: 3
Expand All @@ -45,22 +45,22 @@ Received:
1st spy call return:

{
- a: '1',
+ a: '4',
- a: '4',
+ a: '1',
}

2nd spy call return:

{
- a: '1',
+ a: '4',
- a: '4',
+ a: '1',
}

3rd spy call return:

{
- a: '1',
+ a: '4',
- a: '4',
+ a: '1',
}


Expand Down