{"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/9ad36f7a2cce60488e6ec52283efb32efddaf93a/cli/js/40_test_snapshot.js#L340-L376","documentation":"assertSnapshot identifies each entry by `<full test name> <counter>` (or an explicit options.name plus counter). If the snapshot file exists but contains no entry for that key, check mode throws AssertionError `Missing snapshot: <name>` (cli/js/40_test_snapshot.js). The file being present but the entry absent points at drift between the tests and the recorded snapshots rather than a missing file.","triggerScenarios":"Renaming a test (the full nested name changes, so old entries no longer match); adding a new assertSnapshot call to an existing test (counters of later assertions shift); deleting or reordering earlier assertions in the same test; using a new options.name; running only a filtered subset of tests that share a snapshot file for the first time after edits.","commonSituations":"Test renamed during a refactor while snapshots stayed stale; an assertion added mid-test shifting every subsequent count; teammates regenerating snapshots on different test versions; explicit names that were changed.","solutions":["Run `deno test --update` to record the missing entry, review the diff, and commit the updated snapshot file.","If tests were renamed or reordered intentionally, --update is the correct fix; if not, revert the test-name change.","Give critical snapshots explicit stable names (`{ name: \"output\" }`) so they do not depend on test names and call ordering.","Ensure each assertSnapshot call site is stable — adding/removing one mid-test shifts the counters of all following entries."],"exampleFix":"// before\nDeno.test(\"renders widget\", async (t) => {\n  await t.assertSnapshot(render()); // depends on full test name + order\n});\n\n// after\nDeno.test(\"renders widget\", async (t) => {\n  await t.assertSnapshot(render(), { name: \"widget-render\" }); // stable key\n});","handlingStrategy":"validation","validationCode":"// Give critical snapshots explicit, stable keys so entries survive test renames:\nawait t.assertSnapshot(value, { name: \"widget-render\" });","typeGuard":null,"tryCatchPattern":"try {\n  await t.assertSnapshot(value);\n} catch (err) {\n  if (String(err.message).startsWith(\"Missing snapshot:\")) {\n    // stale snapshot store — regenerate intentionally:\n    // deno test --update\n  }\n  throw err;\n}","preventionTips":["After renaming tests, adding, removing, or reordering assertSnapshot calls, run `deno test --update` and review the snapshot diff.","Use explicit { name: \"...\" } options for snapshots whose identity must not depend on the full test name and call order.","Keep one assertSnapshot per logical check; remember every call in a test increments a shared counter."],"tags":["deno","deno-test","snapshot","assertion","missing-entry"],"backgroundTag":"missing-snapshot","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}