jestjs/jest · error · Error

Error: `.each` called with an empty Array of table data.

Error message

Error: `.each` called with an empty Array of table data.

What it means

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.

Source

Thrown at packages/jest-each/src/validation.ts:42

          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;
const isEmptyString = (str: string | unknown) =>
  typeof str === 'string' && str.trim() === '';

export const validateTemplateTableArguments = (
  headings: Array<string>,
  data: TemplateData,
): void => {
  const incompleteData = data.length % headings.length;
  const missingData = headings.length - incompleteData;

  if (incompleteData > 0) {

View on GitHub (pinned to f49721c78e)

Solutions

  1. Confirm the data source actually contains rows; log the array length before the `.each` call.
  2. Provide a fallback fixture or skip the suite when the source is genuinely empty.
  3. If the empty case is valid, guard the block: `if (rows.length) describe.each(rows)(...)`.

Example fix

// before
const rows = loadFixture('cases.csv'); // empty in CI
it.each(rows)('case %j', (r) => {});

// after
const rows = loadFixture('cases.csv');
console.error('rows:', rows.length);
(rows.length ? it.each(rows) : it.skip.each(rows || [[]]))('case %j', (r) => {});
Defensive patterns

Strategy: validation

Validate before calling

if (!Array.isArray(rows) || rows.length === 0) {
  throw new Error('cannot parameterize over an empty table');
}
it.each(rows)(...);

Type guard

const isNonEmptyArray = (t: unknown): t is unknown[] => Array.isArray(t) && t.length > 0;

Prevention

When it happens

Trigger: Passing a freshly-declared `[]`, or a computed array that resolved to empty, to `.each`.

Common situations: 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.

Related errors


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