Matchers
Overview of all snapshot matchers.
Overview
vitest-snap extends Vitest's expect with four snapshot matchers. Each matcher serializes
the received value to a file and diffs it on subsequent runs using Vitest's built-in
toMatchFileSnapshot.
| Matcher | Input type | Output format |
|---|---|---|
toTextSnapshot | string (or coercible) | Plain text file |
toJsonSnapshot | Any object or primitive | Formatted JSON file |
toYamlSnapshot | Any object or primitive | YAML file |
toMarkdownSnapshot | Object / array of objects | Markdown table file |
Common behaviour
All three matchers:
- Auto-name snapshot files from the current test name (slugified to lowercase).
- Accept an optional
optionsobject to override the output directory, filename, and more. - Are async — always
awaitthe call.
await expect(value).toJsonSnapshot();File path resolution
Snapshot files are written relative to the test file:
<dir>/<slugified-test-name>[_arg1_arg2...]?[.ext]dirdefaults to./snapshots.argsappends extra segments to distinguish parametric snapshots.fileExtensionis appended as-is (leading dot is optional).
Last updated on