jestjs/jest · error · Error
Jest: Couldn't locate all inline snapshots.
Error message
Jest: Couldn't locate all inline snapshots.
What it means
Thrown by `traverseAst` (utils.ts:427-429) after walking the AST if `remainingSnapshots` is non-empty - i.e. at least one inline snapshot recorded by the test run could not be matched to a `CallExpression` in the parsed source. Jest collected snapshots to write during the run but cannot find where to write at least one of them.
Source
Thrown at packages/jest-snapshot/src/utils.ts:428
({type}) => type === 'TemplateLiteral' || type === 'StringLiteral',
);
const {snapshot} = inlineSnapshot;
remainingSnapshots.delete(snapshot);
const replacementNode = templateLiteral(
[templateElement({raw: escapeBacktickString(snapshot)})],
[],
);
if (snapshotIndex === -1) {
args.push(replacementNode);
} else {
args[snapshotIndex] = replacementNode;
}
});
if (remainingSnapshots.size > 0) {
throw new Error("Jest: Couldn't locate all inline snapshots.");
}
};
View on GitHub (pinned to f49721c78e)
Solutions
- Re-run the test suite once the file is stable on disk (no concurrent edits).
- Avoid renaming/re-exporting the snapshot matcher; call `toMatchInlineSnapshot`/`toThrowErrorMatchingInlineSnapshot` by their literal names at the call site.
- Avoid computed member access (`expect(x)[dynamicName]()`) for snapshot assertions.
- If the call lives in a shared helper, inline it or move to `toMatchSnapshot()` (file-based, no AST patching).
Example fix
// before: matcher imported under an alias invisible to the patcher
import { toMatchInlineSnapshot as snap } from '@jest/expect';
expect(value).snap();
// after
expect(value).toMatchInlineSnapshot(); Defensive patterns
Strategy: validation
Validate before calling
// Verify every InlineSnapshot call has a literal callee property name in source
const ast = babel.parseSync(source, { filename });
let ok = true;
traverse(ast, {
CallExpression(p) {
const callee = p.node.callee;
if (callee.type === 'MemberExpression' && /InlineSnapshot$/.test(callee.property.name || '') && callee.computed)
ok = false;
},
});
if (!ok) throw new Error('inline snapshot called via computed/aliased name'); Prevention
- Call toMatchInlineSnapshot/toThrowErrorMatchingInlineSnapshot by literal name at the call site.
- Don't re-export or alias the snapshot matchers.
- Don't edit the test file while a run is in progress; disable format-on-save during -u runs.
When it happens
Trigger: The test source on disk no longer contains the matcher call (file edited while tests run), the matcher is invoked through a dynamically-constructed callee the AST traversal cannot recognize (e.g. `expect(x)[methodName]()` with a computed property), or the matcher was imported under an aliased/different name not literally present at the call site.
Common situations: IDE auto-save rewrites the test file mid-run; using a custom matcher name re-exported from another module (the patcher only recognizes names literally present in the AST per the CLAUDE.md note); a macro or codegen step produces the call at runtime but not in source; race between parallel test runs writing the same file.
Related errors
- Jest: Multiple inline snapshots for the same call are not su
- 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/72a73fea1df6e1ba.json.
Report an issue: GitHub.