{"record":{"id":"29ad35dfd304784b","repo":"jestjs/jest","slug":"each-must-only-be-called-with-an-array-or-tagge","errorCode":null,"errorMessage":"`.each` must only be called with an Array or Tagged Template Literal.","messagePattern":"`\\.each` must only be called with an Array or Tagged Template Literal\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/jest-each/src/index.ts","lineNumber":21,"sourceCode":" *\n * This source code is licensed under the MIT license found in the\n * LICENSE file in the root directory of this source tree.\n *\n */\n\nimport type {Global} from '@jest/types';\nimport bind from './bind';\n\ntype Global = Global.Global;\nconst install = (\n  g: Global,\n  table: Global.EachTable,\n  ...data: Global.TemplateData\n) => {\n  const bindingWithArray = data.length === 0;\n  const bindingWithTemplate = Array.isArray(table) && !!(table as any).raw;\n  if (!bindingWithArray && !bindingWithTemplate) {\n    throw new Error(\n      '`.each` must only be called with an Array or Tagged Template Literal.',\n    );\n  }\n  const test = (\n    title: string,\n    test: Global.EachTestFn<Global.TestFn>,\n    timeout?: number,\n  ) => bind(g.test)(table, ...data)(title, test, timeout);\n  test.skip = bind(g.test.skip)(table, ...data);\n  test.only = bind(g.test.only)(table, ...data);\n\n  const testConcurrent = (\n    title: string,\n    test: Global.EachTestFn<Global.TestFn>,\n    timeout?: number,\n  ) => bind(g.test.concurrent)(table, ...data)(title, test, timeout);\n\n  test.concurrent = testConcurrent;","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/jestjs/jest/blob/8e6d128e4a278059ecddecaa97400b04c8ae5fd9/packages/jest-each/src/index.ts#L3-L39","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure the first argument to `.each` is an Array (e.g. `[[1,2],[3,4]]` or `[{a:1}]`).","If using tagged template syntax, use backtick syntax: `` test.each`a | b ${1} | ${2}` ``.","Check that the variable holding the table data is defined and is an array before passing it."],"exampleFix":"// before\nconst data = { a: 1, b: 2 };\ntest.each(data)('test %j', (val) => { ... });\n\n// after\nconst data = [[1, 2], [3, 4]];\ntest.each(data)('test %j', (val) => { ... });","handlingStrategy":"type-guard","validationCode":"// Validate before calling .each\nfunction assertEachTable(table, ...data) {\n  const isPlainArray = Array.isArray(table) && !table.raw;\n  const isTemplate = Array.isArray(table) && !!table.raw;\n  const isCallWithData = data.length > 0;\n  if (!isPlainArray && !isTemplate && !isCallWithData) {\n    throw new TypeError('.each requires an Array or Tagged Template Literal');\n  }\n}","typeGuard":"function isValidEachTable(table: unknown): table is unknown[] {\n  return Array.isArray(table);\n}","tryCatchPattern":null,"preventionTips":["Always pass an array literal or tagged template to .each.","Use TypeScript — the Global.EachTable type will flag non-array inputs at compile time.","Double-check variable names when passing dynamic data to .each."],"tags":["jest-each","parameterized-tests","validation","api-misuse"],"backgroundTag":null,"analyzedSha":"8e6d128e4a278059ecddecaa97400b04c8ae5fd9","analyzedAt":"2026-08-10T18:11:27.960Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}