{"record":{"id":"39069c4f33e9186f","repo":"jestjs/jest","slug":"error-each-called-with-an-empty-array-of-table","errorCode":null,"errorMessage":"Error: `.each` called with an empty Array of table data.\n","messagePattern":"Error: `\\.each` called with an empty Array of table data\\.\n","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/jest-each/src/validation.ts","lineNumber":42,"sourceCode":"          min: true,\n        })}\\n`,\n    );\n  }\n\n  if (isTaggedTemplateLiteral(table)) {\n    if (isEmptyString(table[0])) {\n      throw new Error(\n        'Error: `.each` called with an empty Tagged Template Literal of table data.\\n',\n      );\n    }\n\n    throw new Error(\n      'Error: `.each` called with a Tagged Template Literal with no data, remember to interpolate with ${expression} syntax.\\n',\n    );\n  }\n\n  if (isEmptyTable(table)) {\n    throw new Error(\n      'Error: `.each` called with an empty Array of table data.\\n',\n    );\n  }\n};\n\nconst isTaggedTemplateLiteral = (array: any) => array.raw !== undefined;\nconst isEmptyTable = (table: Array<unknown>) => table.length === 0;\nconst isEmptyString = (str: string | unknown) =>\n  typeof str === 'string' && str.trim() === '';\n\nexport const validateTemplateTableArguments = (\n  headings: Array<string>,\n  data: TemplateData,\n): void => {\n  const incompleteData = data.length % headings.length;\n  const missingData = headings.length - incompleteData;\n\n  if (incompleteData > 0) {","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/jestjs/jest/blob/8e6d128e4a278059ecddecaa97400b04c8ae5fd9/packages/jest-each/src/validation.ts#L24-L60","documentation":"Thrown by `validateArrayTable` when the array passed to `.each` has zero elements (`table.length === 0`). An empty table means no test cases will be generated, which is almost certainly a mistake — the developer likely forgot to populate the data.","triggerScenarios":"Passing `[]` to `test.each([])`. Passing a variable that was initialized as an empty array but never populated (e.g. from a filtered/mapped result that yielded nothing).","commonSituations":"Filtering test data dynamically and the filter eliminates all rows. Loading data from an external source that returned an empty result. Placeholder/scaffold code left with `[]`.","solutions":["Populate the array with at least one test case row.","If the array is dynamically generated, add a guard to skip the `describe.each`/`test.each` block when the array is empty.","Check the data source or filter logic to ensure rows are present."],"exampleFix":"// before\nconst cases = fixtures.filter(f => f.active); // empty if none active\ntest.each(cases)('test %j', (c) => {});\n\n// after\nconst cases = fixtures.filter(f => f.active);\nif (cases.length > 0) {\n  test.each(cases)('test %j', (c) => {});\n}","handlingStrategy":"validation","validationCode":"// Guard dynamic .each arrays\nfunction runEachIfData(testFn, table) {\n  if (!Array.isArray(table) || table.length === 0) {\n    console.warn('Skipping .each — table is empty');\n    return;\n  }\n  return testFn(table);\n}","typeGuard":"function isNonEmptyArray<T>(value: unknown): value is T[] {\n  return Array.isArray(value) && value.length > 0;\n}","tryCatchPattern":null,"preventionTips":["When generating test data dynamically, guard the .each call with a length check.","Log or warn when test data sources produce zero rows.","In CI, fail if expected test case counts drop to zero unexpectedly."],"tags":["jest-each","parameterized-tests","validation","empty-data"],"backgroundTag":null,"analyzedSha":"8e6d128e4a278059ecddecaa97400b04c8ae5fd9","analyzedAt":"2026-08-10T18:11:27.960Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}