jestjs/jest · error · Error

`.each` must only be called with an Array or Tagged…

Error message

`.each` must only be called with an Array or Tagged Template Literal.

What it means

Thrown by the `.each` binding installer when the table argument is neither a plain array (no `.raw` property) nor a tagged template literal. The check is `bindingWithArray` (no extra data args) or `bindingWithTemplate` (array with `.raw`). If neither condition holds, the call form is invalid.

Solutions

  1. Ensure the first argument to `.each` is an Array (e.g. `[[1,2],[3,4]]` or `[{a:1}]`).
  2. If using tagged template syntax, use backtick syntax: `` test.each`a | b ${1} | ${2}` ``.
  3. Check that the variable holding the table data is defined and is an array before passing it.

Example fix

// before
const data = { a: 1, b: 2 };
test.each(data)('test %j', (val) => { ... });

// after
const data = [[1, 2], [3, 4]];
test.each(data)('test %j', (val) => { ... });
Defensive patterns

Strategy: type-guard

Validate before calling

// Validate before calling .each
function assertEachTable(table, ...data) {
  const isPlainArray = Array.isArray(table) && !table.raw;
  const isTemplate = Array.isArray(table) && !!table.raw;
  const isCallWithData = data.length > 0;
  if (!isPlainArray && !isTemplate && !isCallWithData) {
    throw new TypeError('.each requires an Array or Tagged Template Literal');
  }
}

Type guard

function isValidEachTable(table: unknown): table is unknown[] {
  return Array.isArray(table);
}

Prevention

When it happens

Trigger: Calling `describe.each` or `test.each` with a non-array value such as an object, string, number, or function. Also triggered when passing extra spread arguments alongside a non-array table, or when the table variable is accidentally undefined/null.

Common situations: Passing an object literal instead of an array of objects to `.each`. Accidentally passing `undefined` because the data variable was misspelled or not yet assigned. Calling `.each(someFunction)` by mistake.

Related errors


AI-assisted analysis of jestjs/jest@8e6d128e4a (2026-08-10). Data as JSON: /api/errors/29ad35dfd304784b. Report an issue: GitHub.

Appendix: source

Thrown at packages/jest-each/src/index.ts:21

 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 *
 */

import type {Global} from '@jest/types';
import bind from './bind';

type Global = Global.Global;
const install = (
  g: Global,
  table: Global.EachTable,
  ...data: Global.TemplateData
) => {
  const bindingWithArray = data.length === 0;
  const bindingWithTemplate = Array.isArray(table) && !!(table as any).raw;
  if (!bindingWithArray && !bindingWithTemplate) {
    throw new Error(
      '`.each` must only be called with an Array or Tagged Template Literal.',
    );
  }
  const test = (
    title: string,
    test: Global.EachTestFn<Global.TestFn>,
    timeout?: number,
  ) => bind(g.test)(table, ...data)(title, test, timeout);
  test.skip = bind(g.test.skip)(table, ...data);
  test.only = bind(g.test.only)(table, ...data);

  const testConcurrent = (
    title: string,
    test: Global.EachTestFn<Global.TestFn>,
    timeout?: number,
  ) => bind(g.test.concurrent)(table, ...data)(title, test, timeout);

  test.concurrent = testConcurrent;

View on GitHub (pinned to 8e6d128e4a)