{"record":{"id":"cb5a310a4fa1abb5","repo":"denoland/deno","slug":"snapshot-does-not-match-diff-actual-expe","errorCode":null,"errorMessage":"Snapshot does not match:\n\n    [Diff] Actual / Expected\n\n${diff}\n\nTo update snapshots, run\n    deno test --update-snapshots [files]...\n","messagePattern":"Snapshot does not match:\n\n    \\[Diff\\] Actual / Expected\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/89f33cbef296a2b287f323d42de54c871fa69c77/cli/js/40_test_snapshot.js#L347-L383","documentation":"AssertionError from assertSnapshot() (cli/js/40_test_snapshot.js): the serialized actual value differs from the stored expected string for that key. The message embeds a [Diff] Actual / Expected block and tells you the recovery command: `deno test --update-snapshots`. This is the intended failure mode of snapshot testing — the diff is the review artifact.","triggerScenarios":"Any change in the snapshotted output: a code change that alters formatting/serialization, dependency upgrades changing error messages or ordering, environment-dependent values (paths, timestamps, random ids) leaking into snapshots, or unordered collections serializing in different orders across runs.","commonSituations":"Intentional output changes during development needing a snapshot refresh; flaky snapshots caused by absolute paths or map iteration order; a dependency bump changing stack traces or default formatting; platform line-ending differences (CRLF vs LF).","solutions":["If the new output is intended, run `deno test --update-snapshots`, inspect the snapshot diff in review, and commit","If the change is unintended, fix the code that produced it — the embedded diff shows exactly what moved","Stabilize flaky inputs before re-recording: normalize paths, freeze time, sort collections, mask randomness in the serializer"],"exampleFix":"# before\ndeno test        # Snapshot does not match: [Diff] Actual / Expected ...\n\n# after (intended change)\ndeno test --update-snapshots\ngit diff -- '**/__snapshot__/**'   # review, then commit","handlingStrategy":"try-catch","validationCode":"// scrub nondeterminism before it reaches the snapshot\nconst stable = (s) => s.replaceAll(Deno.cwd(), \"<cwd>\").replace(/\\d{4}-\\d{2}-\\d{2}T[^\\s\"]+/g, \"<ts>\");\nawait t.assertSnapshot(value, { serializer: (v) => stable(String(v)) });","typeGuard":null,"tryCatchPattern":"import { AssertionError } from \"jsr:@std/assert\";\ntry {\n  await t.assertSnapshot(value);\n} catch (err) {\n  if (err instanceof AssertionError && err.message.includes(\"Snapshot does not match\")) {\n    // surface the embedded diff for custom reporting, then decide: fix code or update\n    throw err;\n  }\n  throw err;\n}","preventionTips":["Treat snapshot diffs as review artifacts: regenerate with --update-snapshots only after confirming the change is intended","Normalize environment-dependent values (paths, timestamps, randomness, map order) in the serializer so snapshots are deterministic","Review the __snapshot__ diff in every PR that touches output-producing code"],"tags":["testing","snapshot","assertion","diff","workflow"],"backgroundTag":null,"analyzedSha":"89f33cbef296a2b287f323d42de54c871fa69c77","analyzedAt":"2026-08-16T07:54:21.310Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}