Snapshot tests make sure the output of functions does not change unexpectedly. expect(value).toMatchSnapshot() compares the value against a reference snapshot file stored alongside the test; a mismatch fails the test, meaning either the change is a bug to fix or the reference snapshot needs updating. Snapshot artifacts should be committed alongside code changes and reviewed as part of code review. toMatchInlineSnapshot() instead stores the snapshot inside the test file, and Vitest modifies the test file directly to fill it in. In watch mode, pressing the u key updates a failed snapshot; the --update or -u CLI flag does the same. In CI (when process.env.CI is truthy) Vitest does not write snapshots by default, and mismatched, missing, or obsolete snapshots fail the run. Rendering is powered by @vitest/pretty-format, the snapshotFormat option configures formatting, and custom serializers or custom snapshot matchers extend it; with async concurrent tests, use expect from the local Test Context. Scope: Vitest. Reviewed October 4, 2026.
Snapshot testing
Document v1 · published by Koskamo editorial · updated 2026-10-04
Source and provenance
- Original source
- vitest.dev
- Published on Koskamo by
- Koskamo editorial
- Citation version
- Document v1
- Reuse
- Original summaries; linked sources retain their own terms.