{"record":{"id":"328f2f149de69f08","repo":"denoland/deno","slug":"missing-snapshot-name","errorCode":null,"errorMessage":"Missing snapshot: ${name}","messagePattern":"Missing snapshot: (.+?)","errorType":"exception","errorClass":"AssertionError","httpStatus":null,"severity":"error","filePath":"cli/js/40_test_snapshot.js","lineNumber":358,"sourceCode":"  const expectedSnapshot = MapPrototypeGet(context.currentValues, name);\n\n  if (getIsUpdateMode()) {\n    if (actualSnapshot !== expectedSnapshot) {\n      MapPrototypeSet(context.updatedValues, name, actualSnapshot);\n      if (!ArrayPrototypeIncludes(context.updatedNames, name)) {\n        ArrayPrototypePush(context.updatedNames, name);\n      }\n    }\n    return;\n  }\n\n  if (!context.fileExists) {\n    throw new AssertionError(\n      getErrorMessage(\"Missing snapshot file.\", options),\n    );\n  }\n  if (expectedSnapshot === undefined) {\n    throw new AssertionError(\n      getErrorMessage(`Missing snapshot: ${name}`, options),\n    );\n  }\n  if (actualSnapshot === expectedSnapshot) {\n    return;\n  }\n  throw new AssertionError(\n    getErrorMessage(\n      getSnapshotNotMatchMessage(actualSnapshot, expectedSnapshot),\n      options,\n    ),\n  );\n}\n\nfunction buildSnapshotFileContent(names, getValue) {\n  const buf = [\"export const snapshot = {};\"];\n  for (const name of new SafeArrayIterator(names)) {\n    const value = getValue(name);","sourceCodeStart":340,"sourceCodeEnd":376,"githubUrl":"https://github.com/denoland/deno/blob/89f33cbef296a2b287f323d42de54c871fa69c77/cli/js/40_test_snapshot.js#L340-L376","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nDeno.test(\"formats config\", async (t) => {\n  await t.assertSnapshot(fmt(a));\n  await t.assertSnapshot(fmt(b)); // newly added → Missing snapshot: formats config 2\n});\n\n// after — record it once, commit the snapshot file\ndeno test --update-snapshots","handlingStrategy":"validation","validationCode":"// keep keys stable across refactors by naming snapshots explicitly\nawait t.step(\"formats config\", async () => {\n  await t.assertSnapshot(a, { name: \"config-a\" });\n  await t.assertSnapshot(b, { name: \"config-b\" });\n});","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["testing","snapshot","assertion","naming","workflow"],"backgroundTag":null,"analyzedSha":"89f33cbef296a2b287f323d42de54c871fa69c77","analyzedAt":"2026-08-16T07:54:21.310Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}