From fb18e9a0264b7691eeb18c647e856c6cbaa8519c Mon Sep 17 00:00:00 2001 From: Ignacio Le Fluk Date: Wed, 13 Apr 2022 07:59:57 -0400 Subject: [PATCH] fix(jest-each): fixes error message with incorrect count of missing arguments (#12464) --- CHANGELOG.md | 1 + .../__snapshots__/template.test.ts.snap | 44 +++++++++---------- packages/jest-each/src/validation.ts | 5 ++- 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 29b70dfadf5b..43db8088d062 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -66,6 +66,7 @@ - `[jest-config, jest-haste-map]` Allow searching for tests in `node_modules` by exposing `retainAllFiles` ([#11084](https://github.com/facebook/jest/pull/11084)) - `[jest-core]` [**BREAKING**] Exit with status `1` if no tests are found with `--findRelatedTests` flag ([#12487](https://github.com/facebook/jest/pull/12487)) - `[jest-each]` `%#` is not replaced with index of the test case ([#12517](https://github.com/facebook/jest/pull/12517)) +- `[jest-each]` Fixes error message with incorrect count of missing arguments ([#12464](https://github.com/facebook/jest/pull/12464)) - `[jest-environment-jsdom]` Make `jsdom` accessible to extending environments again ([#12232](https://github.com/facebook/jest/pull/12232)) - `[jest-environment-jsdom]` Log JSDOM errors more cleanly ([#12386](https://github.com/facebook/jest/pull/12386)) - `[jest-environment-node]` Add `MessageChannel`, `MessageEvent` to globals ([#12553](https://github.com/facebook/jest/pull/12553)) diff --git a/packages/jest-each/src/__tests__/__snapshots__/template.test.ts.snap b/packages/jest-each/src/__tests__/__snapshots__/template.test.ts.snap index c4e912980be2..bf551eeec425 100644 --- a/packages/jest-each/src/__tests__/__snapshots__/template.test.ts.snap +++ b/packages/jest-each/src/__tests__/__snapshots__/template.test.ts.snap @@ -54,7 +54,7 @@ Received: 1, ] -Missing 2 arguments" +Missing 1 argument" `; exports[`jest-each .describe throws error when there are fewer arguments than headings when given one row 1`] = ` @@ -67,7 +67,7 @@ Received: 1, ] -Missing 2 arguments" +Missing 1 argument" `; exports[`jest-each .describe throws error when there are no arguments for given headings 1`] = ` @@ -129,7 +129,7 @@ Received: 1, ] -Missing 2 arguments" +Missing 1 argument" `; exports[`jest-each .describe.only throws error when there are fewer arguments than headings when given one row 1`] = ` @@ -142,7 +142,7 @@ Received: 1, ] -Missing 2 arguments" +Missing 1 argument" `; exports[`jest-each .describe.only throws error when there are no arguments for given headings 1`] = ` @@ -204,7 +204,7 @@ Received: 1, ] -Missing 2 arguments" +Missing 1 argument" `; exports[`jest-each .fdescribe throws error when there are fewer arguments than headings when given one row 1`] = ` @@ -217,7 +217,7 @@ Received: 1, ] -Missing 2 arguments" +Missing 1 argument" `; exports[`jest-each .fdescribe throws error when there are no arguments for given headings 1`] = ` @@ -279,7 +279,7 @@ Received: 1, ] -Missing 2 arguments" +Missing 1 argument" `; exports[`jest-each .fit throws error when there are fewer arguments than headings when given one row 1`] = ` @@ -292,7 +292,7 @@ Received: 1, ] -Missing 2 arguments" +Missing 1 argument" `; exports[`jest-each .fit throws error when there are no arguments for given headings 1`] = ` @@ -354,7 +354,7 @@ Received: 1, ] -Missing 2 arguments" +Missing 1 argument" `; exports[`jest-each .it throws error when there are fewer arguments than headings when given one row 1`] = ` @@ -367,7 +367,7 @@ Received: 1, ] -Missing 2 arguments" +Missing 1 argument" `; exports[`jest-each .it throws error when there are no arguments for given headings 1`] = ` @@ -429,7 +429,7 @@ Received: 1, ] -Missing 2 arguments" +Missing 1 argument" `; exports[`jest-each .it.only throws error when there are fewer arguments than headings when given one row 1`] = ` @@ -442,7 +442,7 @@ Received: 1, ] -Missing 2 arguments" +Missing 1 argument" `; exports[`jest-each .it.only throws error when there are no arguments for given headings 1`] = ` @@ -504,7 +504,7 @@ Received: 1, ] -Missing 2 arguments" +Missing 1 argument" `; exports[`jest-each .test throws error when there are fewer arguments than headings when given one row 1`] = ` @@ -517,7 +517,7 @@ Received: 1, ] -Missing 2 arguments" +Missing 1 argument" `; exports[`jest-each .test throws error when there are no arguments for given headings 1`] = ` @@ -579,7 +579,7 @@ Received: 1, ] -Missing 2 arguments" +Missing 1 argument" `; exports[`jest-each .test.concurrent throws error when there are fewer arguments than headings when given one row 1`] = ` @@ -592,7 +592,7 @@ Received: 1, ] -Missing 2 arguments" +Missing 1 argument" `; exports[`jest-each .test.concurrent throws error when there are no arguments for given headings 1`] = ` @@ -654,7 +654,7 @@ Received: 1, ] -Missing 2 arguments" +Missing 1 argument" `; exports[`jest-each .test.concurrent.only throws error when there are fewer arguments than headings when given one row 1`] = ` @@ -667,7 +667,7 @@ Received: 1, ] -Missing 2 arguments" +Missing 1 argument" `; exports[`jest-each .test.concurrent.only throws error when there are no arguments for given headings 1`] = ` @@ -729,7 +729,7 @@ Received: 1, ] -Missing 2 arguments" +Missing 1 argument" `; exports[`jest-each .test.concurrent.skip throws error when there are fewer arguments than headings when given one row 1`] = ` @@ -742,7 +742,7 @@ Received: 1, ] -Missing 2 arguments" +Missing 1 argument" `; exports[`jest-each .test.concurrent.skip throws error when there are no arguments for given headings 1`] = ` @@ -804,7 +804,7 @@ Received: 1, ] -Missing 2 arguments" +Missing 1 argument" `; exports[`jest-each .test.only throws error when there are fewer arguments than headings when given one row 1`] = ` @@ -817,7 +817,7 @@ Received: 1, ] -Missing 2 arguments" +Missing 1 argument" `; exports[`jest-each .test.only throws error when there are no arguments for given headings 1`] = ` diff --git a/packages/jest-each/src/validation.ts b/packages/jest-each/src/validation.ts index 036d3261f726..a2b0088cb2b4 100644 --- a/packages/jest-each/src/validation.ts +++ b/packages/jest-each/src/validation.ts @@ -54,9 +54,10 @@ export const validateTemplateTableArguments = ( headings: Array, data: TemplateData, ): void => { - const missingData = data.length % headings.length; + const incompleteData = data.length % headings.length; + const missingData = headings.length - incompleteData; - if (missingData > 0) { + if (incompleteData > 0) { throw new Error( `Not enough arguments supplied for given headings:\n${EXPECTED_COLOR( headings.join(' | '),