{"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/f49721c78e195558b40913977c9230f5b7f559d8/packages/jest-each/src/validation.ts#L24-L60","documentation":"validateArrayTable rejects an empty array `[]` because there are no rows to generate tests from. Running `.each([])` would silently produce zero test cases, masking the mistake, so jest-each fails fast at validation.ts:42.","triggerScenarios":"Passing a freshly-declared `[]`, or a computed array that resolved to empty, to `.each`.","commonSituations":"A filter/map returns no rows for the current input; an empty CSV/JSON fixture; a data source that is empty in CI but populated locally; refactoring that drops the population step.","solutions":["Confirm the data source actually contains rows; log the array length before the `.each` call.","Provide a fallback fixture or skip the suite when the source is genuinely empty.","If the empty case is valid, guard the block: `if (rows.length) describe.each(rows)(...)`."],"exampleFix":"// before\nconst rows = loadFixture('cases.csv'); // empty in CI\nit.each(rows)('case %j', (r) => {});\n\n// after\nconst rows = loadFixture('cases.csv');\nconsole.error('rows:', rows.length);\n(rows.length ? it.each(rows) : it.skip.each(rows || [[]]))('case %j', (r) => {});","handlingStrategy":"validation","validationCode":"if (!Array.isArray(rows) || rows.length === 0) {\n  throw new Error('cannot parameterize over an empty table');\n}\nit.each(rows)(...);","typeGuard":"const isNonEmptyArray = (t: unknown): t is unknown[] => Array.isArray(t) && t.length > 0;","tryCatchPattern":null,"preventionTips":["Load fixtures with a known non-empty shape in CI.","Assert row count in a precheck before .each.","Skip suites explicitly when data is legitimately empty."],"tags":["jest-each","parameterized-tests","validation","fixtures"],"analyzedSha":"f49721c78e195558b40913977c9230f5b7f559d8","analyzedAt":"2026-08-03T20:16:28.571Z","schemaVersion":2}