{"id":"06007e15a7b5207b","repo":"jestjs/jest","slug":"error-each-called-with-an-empty-tagged-templat","errorCode":null,"errorMessage":"Error: `.each` called with an empty Tagged Template Literal of table data.\n","messagePattern":"Error: `\\.each` called with an empty Tagged Template Literal of table data\\.\n","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/jest-each/src/validation.ts","lineNumber":31,"sourceCode":"type TemplateData = Global.TemplateData;\n\nconst EXPECTED_COLOR = chalk.green;\nconst RECEIVED_COLOR = chalk.red;\n\nexport const validateArrayTable = (table: unknown): void => {\n  if (!Array.isArray(table)) {\n    throw new TypeError(\n      '`.each` must be called with an Array or Tagged Template Literal.\\n\\n' +\n        `Instead was called with: ${pretty(table, {\n          maxDepth: 1,\n          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;","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/jestjs/jest/blob/f49721c78e195558b40913977c9230f5b7f559d8/packages/jest-each/src/validation.ts#L13-L49","documentation":"When jest-each detects a tagged-template call (table has a `.raw` property) but the first template string is empty/whitespace, the table has no headings and no rows, so it throws at validation.ts:31. An empty template means there is nothing to parameterize over.","triggerScenarios":"Writing `.each\\`  \\`` or `.each\\`\\`` (a backtick call with no content) and then attaching a test body.","commonSituations":"Leftover placeholder from scaffolding a test; refactoring that removed the table content but kept the backtick call; merge artifacts.","solutions":["Provide a header row and at least one data row, e.g. `.each\\`a | b\\n${1} | ${2}\\``.","If the test is not meant to be parameterized, drop `.each` and use a normal `it`.","Generate the template from a known-good data source so it is never empty."],"exampleFix":"// before\nit.each``\n  ('works', () => {});\n\n// after\nit.each`\n  a  | b\n  ${1} | ${2}\n`('works for $a / $b', ({a, b}) => {});","handlingStrategy":"validation","validationCode":"// guard a generated tagged template\nfunction buildEach(header, rows) {\n  if (!header || !header.trim()) throw new Error('empty .each template header');\n  // construct the template safely\n}","typeGuard":"const isNonEmptyTemplate = (t: TemplateStringsArray) => typeof t[0] === 'string' && t[0].trim() !== '';","tryCatchPattern":null,"preventionTips":["Never leave an empty backtick .each placeholder.","Lint for .each`` patterns.","Generate templates from data so headers are never blank."],"tags":["jest-each","parameterized-tests","tagged-template","validation"],"analyzedSha":"f49721c78e195558b40913977c9230f5b7f559d8","analyzedAt":"2026-08-03T20:16:28.571Z","schemaVersion":2}