{"record":{"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/8e6d128e4a278059ecddecaa97400b04c8ae5fd9/packages/jest-each/src/validation.ts#L13-L49","documentation":"Thrown when `.each` is called with a tagged template literal whose first string segment (`table[0]`) is empty after trimming. This means the template literal contains no heading text at all, so there is no structure to parse column names from.","triggerScenarios":"Writing `` test.each`` `` (empty backticks with no content and no interpolations). The tagged template literal produces `['']` with `.raw = ['']`, and `isEmptyString('')` returns true.","commonSituations":"Accidentally leaving the template literal empty while scaffolding. A code-generation tool emitting an incomplete `.each` block. Copy-paste error leaving the template body blank.","solutions":["Provide heading text in the template: `` test.each`a | b\\n ${1} | ${2}` ``.","If you do not need headings, use array syntax instead: `test.each([[1, 2]])`."],"exampleFix":"// before\ntest.each``('test', () => {});\n\n// after\ntest.each`a | b\n  ${1} | ${2}`('test $a', ({a, b}) => {});","handlingStrategy":"validation","validationCode":"// For tagged template .each, validate the first segment is non-empty\nfunction validateTemplateNotEmpty(templateStrings) {\n  if (templateStrings[0] && templateStrings[0].trim() === '') {\n    throw new Error('Template literal for .each must contain heading text');\n  }\n}","typeGuard":"function isNonEmptyTemplateString(arr: unknown): arr is TemplateStringsArray {\n  return Array.isArray(arr) && typeof (arr as any[])[0] === 'string' && (arr as any[])[0].trim() !== '';\n}","tryCatchPattern":null,"preventionTips":["Always include a heading row when using tagged template .each syntax.","Prefer array syntax for simple single-column test data.","Use a linter rule or code snippet template for .each to avoid empty templates."],"tags":["jest-each","parameterized-tests","validation","tagged-template"],"backgroundTag":null,"analyzedSha":"8e6d128e4a278059ecddecaa97400b04c8ae5fd9","analyzedAt":"2026-08-10T18:11:27.960Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}