jestjs/jest · error · Error
Error: `.each` called with an empty Tagged Template Literal…
Error message
Error: `.each` called with an empty Tagged Template Literal of table data.
What it means
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.
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]])`.
Example fix
// before
test.each``('test', () => {});
// after
test.each`a | b
${1} | ${2}`('test $a', ({a, b}) => {}); Defensive patterns
Strategy: validation
Validate before calling
// For tagged template .each, validate the first segment is non-empty
function validateTemplateNotEmpty(templateStrings) {
if (templateStrings[0] && templateStrings[0].trim() === '') {
throw new Error('Template literal for .each must contain heading text');
}
} Type guard
function isNonEmptyTemplateString(arr: unknown): arr is TemplateStringsArray {
return Array.isArray(arr) && typeof (arr as any[])[0] === 'string' && (arr as any[])[0].trim() !== '';
} Prevention
- 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.
When it happens
Trigger: Writing `` test.each`` `` (empty backticks with no content and no interpolations). The tagged template literal produces `['']` with `.raw = ['']`, and `isEmptyString('')` returns true.
Common situations: 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.
Related errors
- Error: `.each` called with a Tagged Template Literal with…
- Not enough arguments supplied for given headings
- Table headings do not conform to expected format: heading1…
- `.each` must be called with an Array or Tagged Template…
- `.each` must only be called with an Array or Tagged…
AI-assisted analysis of jestjs/jest@8e6d128e4a (2026-08-10).
Data as JSON: /api/errors/06007e15a7b5207b.
Report an issue: GitHub.
Appendix: source
Thrown at packages/jest-each/src/validation.ts:31
type TemplateData = Global.TemplateData;
const EXPECTED_COLOR = chalk.green;
const RECEIVED_COLOR = chalk.red;
export const validateArrayTable = (table: unknown): void => {
if (!Array.isArray(table)) {
throw new TypeError(
'`.each` must be called with an Array or Tagged Template Literal.\n\n' +
`Instead was called with: ${pretty(table, {
maxDepth: 1,
min: true,
})}\n`,
);
}
if (isTaggedTemplateLiteral(table)) {
if (isEmptyString(table[0])) {
throw new Error(
'Error: `.each` called with an empty Tagged Template Literal of table data.\n',
);
}
throw new Error(
'Error: `.each` called with a Tagged Template Literal with no data, remember to interpolate with ${expression} syntax.\n',
);
}
if (isEmptyTable(table)) {
throw new Error(
'Error: `.each` called with an empty Array of table data.\n',
);
}
};
const isTaggedTemplateLiteral = (array: any) => array.raw !== undefined;
const isEmptyTable = (table: Array<unknown>) => table.length === 0;View on GitHub (pinned to 8e6d128e4a)