{"id":"189d603a0e2d9206","repo":"jestjs/jest","slug":"jest-multiple-inline-snapshots-for-the-same-call","errorCode":null,"errorMessage":"Jest: Multiple inline snapshots for the same call are not supported.","messagePattern":"Jest: Multiple inline snapshots for the same call are not supported\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/jest-snapshot/src/utils.ts","lineNumber":400,"sourceCode":"\n  traverseFast(ast, (node: Node) => {\n    if (node.type !== 'CallExpression') return;\n\n    const {arguments: args, callee} = node;\n    if (\n      callee.type !== 'MemberExpression' ||\n      callee.property.type !== 'Identifier' ||\n      callee.property.loc == null\n    ) {\n      return;\n    }\n    const {line, column} = callee.property.loc.start;\n    const snapshotsForFrame = groupedSnapshots[`${line}:${column}`];\n    if (!snapshotsForFrame) {\n      return;\n    }\n    if (snapshotsForFrame.length > 1) {\n      throw new Error(\n        'Jest: Multiple inline snapshots for the same call are not supported.',\n      );\n    }\n    const inlineSnapshot = snapshotsForFrame[0];\n    inlineSnapshot.node = node;\n\n    snapshotMatcherNames.push(callee.property.name);\n\n    const snapshotIndex = args.findIndex(\n      ({type}) => type === 'TemplateLiteral' || type === 'StringLiteral',\n    );\n\n    const {snapshot} = inlineSnapshot;\n    remainingSnapshots.delete(snapshot);\n    const replacementNode = templateLiteral(\n      [templateElement({raw: escapeBacktickString(snapshot)})],\n      [],\n    );","sourceCodeStart":382,"sourceCodeEnd":418,"githubUrl":"https://github.com/jestjs/jest/blob/f49721c78e195558b40913977c9230f5b7f559d8/packages/jest-snapshot/src/utils.ts#L382-L418","documentation":"Thrown by `traverseAst` (utils.ts:399-403) when more than one inline snapshot is grouped under the same call-frame key (`${line}:${column-1}`). Jest keys inline snapshots by their source position; two snapshots sharing one position means the patcher cannot decide which template literal to write where, so it refuses rather than guess.","triggerScenarios":"Two `toMatchInlineSnapshot()` / `toThrowErrorMatchingInlineSnapshot()` calls whose source-frame line and column collide after the column-1 offset, e.g. multiple inline-snapshot assertions legitimately on the same source position, or a single `expect()` followed by chained calls that map to one frame.","commonSituations":"Calling `toMatchInlineSnapshot()` twice on the same `expect()` chain; helper functions that wrap an inline-snapshot assertion and are called in a way that confuses frame resolution; source maps that collapse multiple calls to the same generated line/column (common with heavy minification or some TypeScript emit).","solutions":["Inspect the test file for any single line containing two `...InlineSnapshot()` calls and split them across lines.","Don't wrap inline-snapshot assertions in helpers that obscure the call frame; inline the assertion at the test site.","If source-map indirection is collapsing frames, switch those assertions to the file-based `toMatchSnapshot()` matcher."],"exampleFix":"// before\nexpect(a).toMatchInlineSnapshot(); expect(b).toMatchInlineSnapshot();\n// after\nexpect(a).toMatchInlineSnapshot();\nexpect(b).toMatchInlineSnapshot();","handlingStrategy":"validation","validationCode":"// Static check: no source line should contain two InlineSnapshot calls\nconst offending = source.split(/\\r?\\n/).filter(l => (l.match(/InlineSnapshot\\(/g) || []).length > 1);\nif (offending.length) throw new Error('split inline snapshots onto separate lines');","typeGuard":null,"tryCatchPattern":null,"preventionTips":["One inline-snapshot assertion per source line; never chain two on a single expect().","Inline the matcher at the test site rather than wrapping in helpers.","If frames collapse due to source maps, switch those tests to toMatchSnapshot()."],"tags":["jest-snapshot","inline-snapshot","ast","user-error"],"analyzedSha":"f49721c78e195558b40913977c9230f5b7f559d8","analyzedAt":"2026-08-03T20:16:28.571Z","schemaVersion":2}