From f50d0b01e6046f2e6532967b24ce6249c37682ed Mon Sep 17 00:00:00 2001 From: Vladimir Sheremet Date: Wed, 3 May 2023 11:56:02 +0200 Subject: [PATCH 1/2] fix: show correct diff in "toHaveBeenCalledWith" --- packages/expect/src/jest-expect.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 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') From d9ac6565bcb4e037ed8578af20664b44e36e0885 Mon Sep 17 00:00:00 2001 From: Vladimir Sheremet Date: Wed, 3 May 2023 12:16:31 +0200 Subject: [PATCH 2/2] test: fix tests --- .../test/__snapshots__/mocked.test.ts.snap | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) 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', }