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
Thrown by `validateArrayTable` when the array passed to `.each` has zero elements (`table.length === 0`). An empty table means no test cases will be generated, which is almost certainly a mistake — the developer likely forgot to populate the data.
Solutions
- Populate the array with at least one test case row.
- If the array is dynamically generated, add a guard to skip the `describe.each`/`test.each` block when the array is empty.
- Check the data source or filter logic to ensure rows are present.
Example fix
// before
const cases = fixtures.filter(f => f.active); // empty if none active
test.each(cases)('test %j', (c) => {});
// after
const cases = fixtures.filter(f => f.active);
if (cases.length > 0) {
test.each(cases)('test %j', (c) => {});
} Defensive patterns
Strategy: validation
Validate before calling
// Guard dynamic .each arrays
function runEachIfData(testFn, table) {
if (!Array.isArray(table) || table.length === 0) {
console.warn('Skipping .each — table is empty');
return;
}
return testFn(table);
} Type guard
function isNonEmptyArray<T>(value: unknown): value is T[] {
return Array.isArray(value) && value.length > 0;
} Prevention
- When generating test data dynamically, guard the .each call with a length check.
- Log or warn when test data sources produce zero rows.
- In CI, fail if expected test case counts drop to zero unexpectedly.
When it happens
Trigger: Passing `[]` to `test.each([])`. Passing a variable that was initialized as an empty array but never populated (e.g. from a filtered/mapped result that yielded nothing).
Common situations: Filtering test data dynamically and the filter eliminates all rows. Loading data from an external source that returned an empty result. Placeholder/scaffold code left with `[]`.
Related errors
- `.each` must be called with an Array or Tagged Template…
- `.each` must only be called with an Array or Tagged…
- Error: `.each` called with a Tagged Template Literal with…
- Error: `.each` called with an empty Tagged Template Literal…
- Not enough arguments supplied for given headings
AI-assisted analysis of jestjs/jest@8e6d128e4a (2026-08-10).
Data as JSON: /api/errors/39069c4f33e9186f.
Report an issue: GitHub.
Appendix: 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 8e6d128e4a)