Skip to content

Commit 19fcd8d

Browse files
authoredMay 3, 2023
fix: show correct diff in "toHaveBeenCalledWith" (#3289)
1 parent a3393b1 commit 19fcd8d

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed
 

‎packages/expect/src/jest-expect.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
356356
msg += c().gray(`\n\nReceived: \n${spy.mock.calls.map((callArg, i) => {
357357
let methodCall = c().bold(` ${ordinalOf(i + 1)} ${spy.getMockName()} call:\n\n`)
358358
if (actualCall)
359-
methodCall += diff(callArg, actualCall, { showLegend: false })
359+
methodCall += diff(actualCall, callArg, { showLegend: false })
360360
else
361361
methodCall += stringify(callArg).split('\n').map(line => ` ${line}`).join('\n')
362362
@@ -370,7 +370,7 @@ export const JestChaiExpect: ChaiPlugin = (chai, utils) => {
370370
msg += c().gray(`\n\nReceived: \n${spy.mock.results.map((callReturn, i) => {
371371
let methodCall = c().bold(` ${ordinalOf(i + 1)} ${spy.getMockName()} call return:\n\n`)
372372
if (actualReturn)
373-
methodCall += diff(callReturn.value, actualReturn, { showLegend: false })
373+
methodCall += diff(actualReturn, callReturn.value, { showLegend: false })
374374
else
375375
methodCall += stringify(callReturn).split('\n').map(line => ` ${line}`).join('\n')
376376

‎test/core/test/__snapshots__/mocked.test.ts.snap

+14-14
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ exports[`mocked function which fails on toReturnWith > just one call 1`] = `
66
Received:
77
1st spy call return:
88
9-
- 1
10-
+ 2
9+
- 2
10+
+ 1
1111
1212
1313
Number of calls: 1
@@ -20,18 +20,18 @@ exports[`mocked function which fails on toReturnWith > multi calls 1`] = `
2020
Received:
2121
1st spy call return:
2222
23-
- 1
24-
+ 2
23+
- 2
24+
+ 1
2525
2626
2nd spy call return:
2727
28-
- 1
29-
+ 2
28+
- 2
29+
+ 1
3030
3131
3rd spy call return:
3232
33-
- 1
34-
+ 2
33+
- 2
34+
+ 1
3535
3636
3737
Number of calls: 3
@@ -45,22 +45,22 @@ Received:
4545
1st spy call return:
4646
4747
{
48-
- a: '1',
49-
+ a: '4',
48+
- a: '4',
49+
+ a: '1',
5050
}
5151
5252
2nd spy call return:
5353
5454
{
55-
- a: '1',
56-
+ a: '4',
55+
- a: '4',
56+
+ a: '1',
5757
}
5858
5959
3rd spy call return:
6060
6161
{
62-
- a: '1',
63-
+ a: '4',
62+
- a: '4',
63+
+ a: '1',
6464
}
6565
6666

0 commit comments

Comments
 (0)
Please sign in to comment.