Skip to content

Commit

Permalink
fix: show correct diff in "toHaveBeenCalledWith" (#3289)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va authored May 3, 2023
1 parent a3393b1 commit 19fcd8d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions packages/expect/src/jest-expect.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit 19fcd8d

Please sign in to comment.