{"record":{"id":"86b9e377b4cf3f99","repo":"avajs/ava","slug":"did-not-match-snapshot","errorCode":null,"errorMessage":"Did not match snapshot","messagePattern":"Did not match snapshot","errorType":"exception","errorClass":"AssertionError","httpStatus":null,"severity":"error","filePath":"lib/assert.js","lineNumber":675,"sourceCode":"\n\t\t\t\tconst improperUsage = {assertion: 'snapshot', name: error.name, snapPath: error.snapPath};\n\t\t\t\tif (error instanceof VersionMismatchError) {\n\t\t\t\t\timproperUsage.snapVersion = error.snapVersion;\n\t\t\t\t\timproperUsage.expectedVersion = error.expectedVersion;\n\t\t\t\t}\n\n\t\t\t\tthrow fail(new AssertionError(message ?? 'Could not compare snapshot', {\n\t\t\t\t\tasssertion: 't.snapshot()',\n\t\t\t\t\timproperUsage,\n\t\t\t\t}));\n\t\t\t}\n\n\t\t\tif (result.pass) {\n\t\t\t\treturn pass();\n\t\t\t}\n\n\t\t\tif (result.actual) {\n\t\t\t\tthrow fail(new AssertionError(message ?? 'Did not match snapshot', {\n\t\t\t\t\tassertion: 't.snapshot()',\n\t\t\t\t\tformattedDetails: [formatDescriptorDiff(result.actual, result.expected, {invert: true})],\n\t\t\t\t}));\n\t\t\t} else {\n\t\t\t\t// This can only occur in CI environments.\n\t\t\t\tthrow fail(new AssertionError(message ?? 'No snapshot available — new snapshots are not created in CI environments', {\n\t\t\t\t\tassertion: 't.snapshot()',\n\t\t\t\t}));\n\t\t\t}\n\t\t});\n\n\t\tthis.truthy = withSkip((actual, message) => {\n\t\t\tassertMessage(message, 't.truthy()');\n\n\t\t\tif (actual) {\n\t\t\t\treturn pass();\n\t\t\t}\n","sourceCodeStart":657,"sourceCodeEnd":693,"githubUrl":"https://github.com/avajs/ava/blob/bbfd946322fdeca2b547a691d947fb4e18c0c67f/lib/assert.js#L657-L693","documentation":"AVA throws this AssertionError from t.snapshot() when the snapshot engine returned a comparison result with result.pass === false and a result.actual descriptor — i.e. the snapshot file was read fine, but the value passed to t.snapshot() differs from the stored snapshot. AVA includes a formatted diff between the actual value and the expected snapshot in formattedDetails.","triggerScenarios":"Calling t.snapshot(value) where value serializes differently from the previously recorded snapshot for this test (same snapshot index/hotpath), e.g. changed output, changed key order or added fields, nondeterministic values (timestamps, random ids, floating point).","commonSituations":"A code change intentionally altered output but snapshots were not updated; inserting/removing a t.snapshot() call shifting snapshot indices so later assertions compare against wrong snapshots; environment-dependent output differing between dev and CI; locale/timezone differences affecting serialized values.","solutions":["If the change is intentional, update snapshots with npx ava --update-snapshots and commit the .snap changes.","Inspect the formatted diff in the error details to decide whether the actual value or the snapshot is wrong; fix the code if the output regressed.","Remove stale entries or reorder t.snapshot() calls after refactoring tests so each call compares against the correct snapshot entry.","Normalize nondeterministic values (freeze time, seed randomness, round floats) before passing them to t.snapshot()."],"exampleFix":"// before\nt.snapshot({updatedAt: new Date()}); // diff fails every run\n\n// after\nt.snapshot({updatedAt: 0}); // or use a fixed clock\n// then: npx ava --update-snapshots","handlingStrategy":"validation","validationCode":"// Normalize nondeterministic values before snapshotting:\nconst stable = (value) => JSON.parse(JSON.stringify(value, (k, v) =>\n  k === 'updatedAt' || k === 'id' ? '<normalised>' : v));\nt.snapshot(stable(result), 'stable result');","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run npx ava --update-snapshots and commit .snap changes whenever you intentionally change output.","Avoid snapshotting timestamps, random ids, or floating-point results directly; normalize them first.","After inserting/removing t.snapshot() calls in a test, regenerate snapshots since indices shift.","Review the diff in the assertion details to distinguish intended changes from regressions before updating snapshots."],"tags":["snapshot","ava","assertion-failed","diff-mismatch"],"backgroundTag":"snapshot-mismatch","analyzedSha":"bbfd946322fdeca2b547a691d947fb4e18c0c67f","analyzedAt":"2026-09-02T01:24:43.834Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}