avajs/ava · error · AssertionError
Did not match snapshot
Error message
Did not match snapshot
What it means
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.
Source
Thrown at lib/assert.js:675
const improperUsage = {assertion: 'snapshot', name: error.name, snapPath: error.snapPath};
if (error instanceof VersionMismatchError) {
improperUsage.snapVersion = error.snapVersion;
improperUsage.expectedVersion = error.expectedVersion;
}
throw fail(new AssertionError(message ?? 'Could not compare snapshot', {
asssertion: 't.snapshot()',
improperUsage,
}));
}
if (result.pass) {
return pass();
}
if (result.actual) {
throw fail(new AssertionError(message ?? 'Did not match snapshot', {
assertion: 't.snapshot()',
formattedDetails: [formatDescriptorDiff(result.actual, result.expected, {invert: true})],
}));
} else {
// This can only occur in CI environments.
throw fail(new AssertionError(message ?? 'No snapshot available — new snapshots are not created in CI environments', {
assertion: 't.snapshot()',
}));
}
});
this.truthy = withSkip((actual, message) => {
assertMessage(message, 't.truthy()');
if (actual) {
return pass();
}
View on GitHub (pinned to bbfd946322)
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().
Example fix
// before
t.snapshot({updatedAt: new Date()}); // diff fails every run
// after
t.snapshot({updatedAt: 0}); // or use a fixed clock
// then: npx ava --update-snapshots Defensive patterns
Strategy: validation
Validate before calling
// Normalize nondeterministic values before snapshotting: const stable = (value) => JSON.parse(JSON.stringify(value, (k, v) => k === 'updatedAt' || k === 'id' ? '<normalised>' : v)); t.snapshot(stable(result), 'stable result');
Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- Cannot record snapshot ${index} for ${JSON.stringify(belongs
- `t.snapshot()` can only be used in tests
- The snapshot assertion message must be a non-empty string
- Could not compare snapshot
- No snapshot available — new snapshots are not created in CI
AI-assisted analysis of avajs/ava@bbfd946322 (2026-09-02).
Data as JSON: /api/errors/86b9e377b4cf3f99.
Report an issue: GitHub.