# Configuration (/docs/matchers/configuration)



Overview [#overview]

Options are merged in this order (last wins):

1. Built-in defaults
2. `configureGlobalSnapOptions` values
3. Per-call `options` argument

Default configuration [#default-configuration]

All matchers share the same built-in defaults:

| Option       | Default                                  | Description                                 |
| ------------ | ---------------------------------------- | ------------------------------------------- |
| `dir`        | `"./snapshots"`                          | Directory relative to test file             |
| `filters`    | `[new UndefinedFilter()]`                | Removes `undefined` props                   |
| `redactions` | `[new ValueRedaction(isDate, "[Date]")]` | Replaces `Date` values with a tag           |
| `indent`     | `2`                                      | Spaces used by `JSON` and `YAML` formatting |

`name`, `fileExtension`, and `args` have no built-in default — they are derived from the test name / left empty unless explicitly set.

Global configuration [#global-configuration]

Use `configureGlobalSnapOptions` in your Vitest setup file to set process-wide defaults:

```ts title="vitest.setup.ts"
import { configureGlobalSnapOptions, NullFilter } from "vitest-snap";

configureGlobalSnapOptions({
  dir: "./__snapshots__",
  filters: [new NullFilter()],
});
```

Register the setup file in your Vitest config:

```ts title="vitest.config.ts"
import { defineConfig } from "vitest/config";

export default defineConfig({
  test: {
    setupFiles: ["./vitest.setup.ts"],
  },
});
```

Global options are shallow-merged with the built-in defaults, then any per-call options are merged on top.

Matcher configuration [#matcher-configuration]

Pass an `options` object as the first argument to any matcher to override options for that single call:

```ts
test("user object", async () => {
  await expect(user).toJsonSnapshot({
    dir: "./__snapshots__",
    name: "my-custom-name",
    fileExtension: "json",
    args: [userId],
    filters: [new NullFilter()],
    redactions: [new ReplacedRedaction(".password", "[REDACTED]")],
    indent: 4,
  });
});
```

Per-call options always win over global and built-in defaults.

All options [#all-options]

| Option          | Type                           | Matchers                   | Description                                                           |
| --------------- | ------------------------------ | -------------------------- | --------------------------------------------------------------------- |
| `dir`           | `string`                       | JSON, Text, YAML, Markdown | Directory (relative to test file) where snapshot files are written    |
| `name`          | `string`                       | JSON, Text, YAML, Markdown | Base filename slug — defaults to slugified test name                  |
| `fileExtension` | `string`                       | JSON, Text, YAML, Markdown | Extension appended to the filename (e.g. `"json"`, `"txt"`)           |
| `args`          | `any[]`                        | JSON, Text, YAML, Markdown | Extra segments for parametric snapshots (e.g. `[pageSize]` → `_50`)   |
| `filters`       | `(Selector<T> \| Filter<T>)[]` | JSON, YAML, Markdown       | Filters applied before serialization — see [Filters](/docs/filters)   |
| `redactions`    | `Redaction<T>[]`               | JSON, YAML, Markdown       | Redactions applied after filters — see [Redactions](/docs/redactions) |
| `indent`        | `number`                       | JSON, YAML                 | Spaces used by `JSON` and `YAML` formatting                           |
