Snapshot tests make sure your UI does not change unexpectedly: render a component with a test renderer into a serializable value, assert it with expect(container.firstChild).toMatchSnapshot(), and Jest compares it against the reference snapshot file stored alongside the test, failing when the two do not match. Commit snapshot artifacts alongside code changes and review them in code review; Jest uses pretty-format to keep them human-readable. After an intentional implementation change, regenerate with jest --updateSnapshot (or the equivalent -u flag), which re-records every failing snapshot — so fix genuine bugs first to avoid recording snapshots of buggy behavior — narrow regeneration to matching tests with --testNamePattern, or step through failures interactively in watch mode. Inline snapshots via .toMatchInlineSnapshot() write values back into the test source; Jest writes them by default and delegates to prettier when the project uses it. For generated fields like IDs and dates that would fail every run, pass property matchers such as expect.any(Date), which are checked before the snapshot is written and stored in place of the received value. Scope: Jest. Reviewed October 4, 2026.
Snapshot testing
Document v1 · published by Koskamo editorial · updated 2026-10-04
Source and provenance
- Original source
- jestjs.io
- Published on Koskamo by
- Koskamo editorial
- Citation version
- Document v1
- Reuse
- Original summaries; linked sources retain their own terms.