{"record":{"id":"06933944324086f3","repo":"denoland/deno","slug":"snapshot-does-not-match-n-n-green-diff","errorCode":null,"errorMessage":"Snapshot does not match:\\n\\n    ${green(\"[Diff]\")} ${green(\"Actual\")} / ${red(\"Expected\")}\\n\\n${diff}\\n\\nTo update snapshots, run\\n    deno test --update-snapshots [files]...\\n","messagePattern":"Snapshot does not match:\\\\n\\\\n    (.+?) (.+?) / (.+?)\\\\n\\\\n(.+?)\\\\n\\\\nTo update snapshots, run\\\\n    deno test --update-snapshots \\[files\\]\\.\\.\\.\\\\n","errorType":"exception","errorClass":"AssertionError","httpStatus":null,"severity":"error","filePath":"cli/js/40_test_snapshot.js","lineNumber":365,"sourceCode":"      }\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);\n    if (value === undefined) {\n      continue;\n    }\n    let formatted = escapeStringForJs(value);\n    formatted = StringPrototypeIncludes(formatted, \"\\n\")\n      ? `\\n${formatted}\\n`\n      : formatted;","sourceCodeStart":347,"sourceCodeEnd":383,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/cli/js/40_test_snapshot.js#L347-L383","documentation":"Thrown by the built-in snapshot testing API (Deno.TestContext.assertSnapshot, implemented in cli/js/40_test_snapshot.js). The actual value serialized during the test no longer matches the string stored in the __snapshots__/*.snap file for that test and snapshot name. The message contains a colored diff plus the exact command needed to regenerate the snapshots.","triggerScenarios":"A snapshot file exists and contains an entry for the snapshot's name (counter-based or set via options.msg), but the current serialized actual value (string or property-based snapshot) is not strictly equal to the stored snapshot string.","commonSituations":"Intentional output changes after a refactor; non-deterministic values captured in snapshots (Date.now(), Math.random(), temp dirs, absolute paths); CRLF vs LF differences across operating systems; tests reordered so counter-based snapshot names now map to different values.","solutions":["Review the diff in the failure output; if the new value is intended, run `deno test --update-snapshots <files>...` and commit the regenerated .snap file","If the change is unintended, fix the code producing the value until it matches the stored snapshot","For non-deterministic inputs, freeze or strip them before snapshotting (fixed dates, seeded RNG, path basenames)","Give distinct names via assertSnapshot(t, value, { msg: 'stable-name' }) so edits and test reordering do not collide with counter-based names"],"exampleFix":"// before\nDeno.test(\"greeting\", async (t) => {\n  await t.assertSnapshot(greet(new Date())); // Date differs every run\n});\n\n// after\nDeno.test(\"greeting\", async (t) => {\n  await t.assertSnapshot(greet(new Date(\"2026-01-01T00:00:00Z\"))); // frozen input\n});","handlingStrategy":"validation","validationCode":"// Keep snapshot inputs deterministic before asserting\nfunction stabilize(value: unknown): unknown {\n  return JSON.stringify(value, (_k, v) =>\n    typeof v === \"string\" && v.includes(Deno.build.os) ? \"<os-dependent>\" : v,\n  );\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Freeze dates and seed RNG before snapshotting","Use assertSnapshot(t, v, { msg: 'stable-name' }) so reordering tests never remaps counter-based snapshots","Never run --update-snapshots in CI; review diffs locally and commit .snap files","Keep absolute paths and machine-specific values out of snapshot inputs"],"tags":["testing","snapshot","assertion","deno-test"],"backgroundTag":"snapshot-mismatch","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}