jestjs/jest · error · Error
Jest: Multiple inline snapshots for the same call are not su
Error message
Jest: Multiple inline snapshots for the same call are not supported.
What it means
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.
Source
Thrown at packages/jest-snapshot/src/utils.ts:400
traverseFast(ast, (node: Node) => {
if (node.type !== 'CallExpression') return;
const {arguments: args, callee} = node;
if (
callee.type !== 'MemberExpression' ||
callee.property.type !== 'Identifier' ||
callee.property.loc == null
) {
return;
}
const {line, column} = callee.property.loc.start;
const snapshotsForFrame = groupedSnapshots[`${line}:${column}`];
if (!snapshotsForFrame) {
return;
}
if (snapshotsForFrame.length > 1) {
throw new Error(
'Jest: Multiple inline snapshots for the same call are not supported.',
);
}
const inlineSnapshot = snapshotsForFrame[0];
inlineSnapshot.node = node;
snapshotMatcherNames.push(callee.property.name);
const snapshotIndex = args.findIndex(
({type}) => type === 'TemplateLiteral' || type === 'StringLiteral',
);
const {snapshot} = inlineSnapshot;
remainingSnapshots.delete(snapshot);
const replacementNode = templateLiteral(
[templateElement({raw: escapeBacktickString(snapshot)})],
[],
);View on GitHub (pinned to f49721c78e)
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.
Example fix
// before expect(a).toMatchInlineSnapshot(); expect(b).toMatchInlineSnapshot(); // after expect(a).toMatchInlineSnapshot(); expect(b).toMatchInlineSnapshot();
Defensive patterns
Strategy: validation
Validate before calling
// Static check: no source line should contain two InlineSnapshot calls
const offending = source.split(/\r?\n/).filter(l => (l.match(/InlineSnapshot\(/g) || []).length > 1);
if (offending.length) throw new Error('split inline snapshots onto separate lines'); Prevention
- 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().
When it happens
Trigger: 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.
Common situations: 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).
Related errors
- Jest: Couldn't locate all inline snapshots.
- Jest: no snapshot insert location found
- jest-snapshot: Failed to parse ${sourceFilePath}
- Could not infer Prettier parser for file ${filepath}
- Could not infer Prettier parser for file ${sourceFilePath}
AI-assisted analysis of jestjs/jest@f49721c78e (2026-08-03).
Data as JSON: /data/errors/189d603a0e2d9206.json.
Report an issue: GitHub.