denoland/deno · error · AssertionError
Missing snapshot: ${name}
Error message
Missing snapshot: ${name} What it means
AssertionError from assertSnapshot() (cli/js/40_test_snapshot.js): the snapshot file exists, but it has no entry for this snapshot's key. Keys are `${testName} ${count}`, derived from the full nested test name and a per-test counter of assertSnapshot calls — so adding, renaming, or reordering snapshot calls invalidates keys.
Source
Thrown at cli/js/40_test_snapshot.js:358
const expectedSnapshot = MapPrototypeGet(context.currentValues, name);
if (getIsUpdateMode()) {
if (actualSnapshot !== expectedSnapshot) {
MapPrototypeSet(context.updatedValues, name, actualSnapshot);
if (!ArrayPrototypeIncludes(context.updatedNames, name)) {
ArrayPrototypePush(context.updatedNames, name);
}
}
return;
}
if (!context.fileExists) {
throw new AssertionError(
getErrorMessage("Missing snapshot file.", options),
);
}
if (expectedSnapshot === undefined) {
throw new AssertionError(
getErrorMessage(`Missing snapshot: ${name}`, options),
);
}
if (actualSnapshot === expectedSnapshot) {
return;
}
throw new AssertionError(
getErrorMessage(
getSnapshotNotMatchMessage(actualSnapshot, expectedSnapshot),
options,
),
);
}
function buildSnapshotFileContent(names, getValue) {
const buf = ["export const snapshot = {};"];
for (const name of new SafeArrayIterator(names)) {
const value = getValue(name);View on GitHub (pinned to 89f33cbef2)
Solutions
- Run `deno test --update-snapshots` to record the new key, then review and commit the diff
- If tests were renamed, expect all their snapshot entries to move — update and commit
- For order/branch-dependent assertions, pass an explicit stable { name: "..." } option so keys don't depend on call order
Example fix
// before
Deno.test("formats config", async (t) => {
await t.assertSnapshot(fmt(a));
await t.assertSnapshot(fmt(b)); // newly added → Missing snapshot: formats config 2
});
// after — record it once, commit the snapshot file
deno test --update-snapshots Defensive patterns
Strategy: validation
Validate before calling
// keep keys stable across refactors by naming snapshots explicitly
await t.step("formats config", async () => {
await t.assertSnapshot(a, { name: "config-a" });
await t.assertSnapshot(b, { name: "config-b" });
}); Prevention
- Pass explicit { name } options for anything order- or branch-dependent instead of relying on the counter
- After renaming tests or adding assertions, re-run with --update-snapshots and review the key churn in the committed diff
When it happens
Trigger: Adding a new t.assertSnapshot() call to an existing test; renaming a test (or any parent step name) so the stored key no longer matches; reordering or conditionally skipping an earlier snapshot call which shifts the counter; asserting different numbers of snapshots per branch.
Common situations: Incremental test growth after snapshots were committed; renaming steps during a refactor; data-dependent control flow (if/else each with snapshots) executed in a different order than when the file was recorded.
Related errors
- Missing snapshot file.
- Snapshot does not match: [Diff] Actual / Expected ${di
- Expected the second argument to assertSnapshot() to be an op
- Snapshot serializer must return a string
- ${prefix}Linter plugin name must only contain lowercase lett
AI-assisted analysis of denoland/deno@89f33cbef2 (2026-08-16).
Data as JSON: /api/errors/328f2f149de69f08.
Report an issue: GitHub.