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

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.

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 f49721c78e)

Solutions

  1. Provide a header row and at least one data row, e.g. `.each\`a | b\n${1} | ${2}\``.
  2. If the test is not meant to be parameterized, drop `.each` and use a normal `it`.
  3. Generate the template from a known-good data source so it is never empty.

Example fix

// before
it.each``
  ('works', () => {});

// after
it.each`
  a  | b
  ${1} | ${2}
`('works for $a / $b', ({a, b}) => {});
Defensive patterns

Strategy: validation

Validate before calling

// guard a generated tagged template
function buildEach(header, rows) {
  if (!header || !header.trim()) throw new Error('empty .each template header');
  // construct the template safely
}

Type guard

const isNonEmptyTemplate = (t: TemplateStringsArray) => typeof t[0] === 'string' && t[0].trim() !== '';

Prevention

When it happens

Trigger: Writing `.each\` \`` or `.each\`\`` (a backtick call with no content) and then attaching a test body.

Common situations: Leftover placeholder from scaffolding a test; refactoring that removed the table content but kept the backtick call; merge artifacts.

Related errors


AI-assisted analysis of jestjs/jest@f49721c78e (2026-08-03). Data as JSON: /data/errors/06007e15a7b5207b.json. Report an issue: GitHub.