# Matchers (/docs/matchers)



Overview [#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`](/docs/matchers/to-text-snapshot)         | `string` (or coercible)   | Plain text file     |
| [`toJsonSnapshot`](/docs/matchers/to-json-snapshot)         | Any object or primitive   | Formatted JSON file |
| [`toYamlSnapshot`](/docs/matchers/to-yaml-snapshot)         | Any object or primitive   | YAML file           |
| [`toMarkdownSnapshot`](/docs/matchers/to-markdown-snapshot) | Object / array of objects | Markdown table file |

Common behaviour [#common-behaviour]

All three matchers:

* **Auto-name** snapshot files from the current test name (slugified to lowercase).
* Accept an optional `options` object to override the output directory, filename, and more.
* Are **async** — always `await` the call.

```ts
await expect(value).toJsonSnapshot();
```

File path resolution [#file-path-resolution]

Snapshot files are written relative to the test file:

```
<dir>/<slugified-test-name>[_arg1_arg2...]?[.ext]
```

* `dir` defaults to `./snapshots`.
* `args` appends extra segments to distinguish parametric snapshots.
* `fileExtension` is appended as-is (leading dot is optional).
