From 19fcd8df8291fdd9b0b4159c76067d0e3ae067eb Mon Sep 17 00:00:00 2001 From: Vladimir Date: Wed, 3 May 2023 14:18:52 +0200 Subject: [PATCH] fix: show correct diff in "toHaveBeenCalledWith" (#3289) --- packages/expect/src/jest-expect.ts | 4 +-- .../test/__snapshots__/mocked.test.ts.snap | 28 +++++++++---------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/packages/expect/src/jest-expect.ts b/packages/expect/src/jest-expect.ts index c9b4e8b84a76..e51f7b8d6420 100644 --- a/packages/expect/src/jest-expect.ts +++ b/packages/expect/src/jest-expect.ts @@ -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') @@ -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') diff --git a/test/core/test/__snapshots__/mocked.test.ts.snap b/test/core/test/__snapshots__/mocked.test.ts.snap index 1fd6b2244e71..b0a115818920 100644 --- a/test/core/test/__snapshots__/mocked.test.ts.snap +++ b/test/core/test/__snapshots__/mocked.test.ts.snap @@ -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 @@ -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 @@ -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', }