From 1688d706b9df36ff63fbdff56aab71b6ed63008e Mon Sep 17 00:00:00 2001 From: Xianming Zhong Date: Tue, 29 May 2018 23:07:10 +0800 Subject: [PATCH 1/4] Fix wrong messages for nthCalledWith --- packages/expect/src/spy_matchers.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/expect/src/spy_matchers.js b/packages/expect/src/spy_matchers.js index f84ddb4a8d68..2a176fb9e1f1 100644 --- a/packages/expect/src/spy_matchers.js +++ b/packages/expect/src/spy_matchers.js @@ -365,7 +365,11 @@ const createNthCalledWithMatcher = (matcherName: string) => ( `Expected ${identifier} ${nthToString( nth, )} call to have been called with:\n` + - formatMismatchedCalls(calls, expected, LAST_CALL_PRINT_LIMIT); + formatMismatchedCalls( + calls[nth - 1] ? [calls[nth - 1]] : [], + expected, + LAST_CALL_PRINT_LIMIT, + ); return {message, pass}; }; From e82cc10dc172ac3983ebf722e55cf228bd00371d Mon Sep 17 00:00:00 2001 From: Xianming Zhong Date: Wed, 30 May 2018 00:11:00 +0800 Subject: [PATCH 2/4] Update the test snapshot --- .../src/__tests__/__snapshots__/spy_matchers.test.js.snap | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/expect/src/__tests__/__snapshots__/spy_matchers.test.js.snap b/packages/expect/src/__tests__/__snapshots__/spy_matchers.test.js.snap index 7934e2030ac5..95a15e70ccf4 100644 --- a/packages/expect/src/__tests__/__snapshots__/spy_matchers.test.js.snap +++ b/packages/expect/src/__tests__/__snapshots__/spy_matchers.test.js.snap @@ -261,7 +261,9 @@ exports[`nthCalledWith should replace 1st, 2nd, 3rd with first, second, third 1` "expect(jest.fn()).nthCalledWith(expected) Expected mock function first call to have been called with: -" + \\"foo\\" +as argument 1, but it was called with + \\"foo1\\"." `; exports[`nthCalledWith should replace 1st, 2nd, 3rd with first, second, third 2`] = ` @@ -1290,7 +1292,9 @@ exports[`toHaveBeenNthCalledWith should replace 1st, 2nd, 3rd with first, second "expect(jest.fn()).toHaveBeenNthCalledWith(expected) Expected mock function first call to have been called with: -" + \\"foo\\" +as argument 1, but it was called with + \\"foo1\\"." `; exports[`toHaveBeenNthCalledWith should replace 1st, 2nd, 3rd with first, second, third 2`] = ` From 320a3cd2ca0bf858e3b6d26420909d27ce3fdcfe Mon Sep 17 00:00:00 2001 From: Xianming Zhong Date: Wed, 30 May 2018 00:13:28 +0800 Subject: [PATCH 3/4] Add changes to CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a68d6486cb6..b4e9fad9a4b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ ### Fixes +* `[expect]` toHaveBeenNthCalledWith/nthCalledWith gives wrong call messages if not matched ([#6338](https://github.com/facebook/jest/pull/6338)) * `[expect]` toMatchObject throws TypeError when a source property is null ([#6313](https://github.com/facebook/jest/pull/6313)) * `[jest-cli]` Normalize slashes in paths in CLI output on Windows ((#6310)[https://github.com/facebook/jest/pull/6310]) From d9c950ff7b92d32bfbdda8b472efa994e81c4cb2 Mon Sep 17 00:00:00 2001 From: Xianming Zhong Date: Wed, 30 May 2018 08:35:37 +0800 Subject: [PATCH 4/4] Update PR number --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b4e9fad9a4b8..9500b2886410 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ ### Fixes -* `[expect]` toHaveBeenNthCalledWith/nthCalledWith gives wrong call messages if not matched ([#6338](https://github.com/facebook/jest/pull/6338)) +* `[expect]` toHaveBeenNthCalledWith/nthCalledWith gives wrong call messages if not matched ([#6340](https://github.com/facebook/jest/pull/6340)) * `[expect]` toMatchObject throws TypeError when a source property is null ([#6313](https://github.com/facebook/jest/pull/6313)) * `[jest-cli]` Normalize slashes in paths in CLI output on Windows ((#6310)[https://github.com/facebook/jest/pull/6310])