vitest-snap

Quick Start

Getting Started with vitest-snap.

Introduction

vitest-snap like its name suggest is a Snapshot testing library based on the Vitest testing framework.

Features

  • Auto-naming — snapshot filenames are derived from the test name automatically; no boilerplate required
  • Parameterised snapshots — pass args to generate distinct snapshot files per test input
  • Filtering & redactions — scrub, replace, remove or sort values before snapshotting with a composable DSL
  • Date redaction by defaultDate instances are replaced with [Date_1], [Date_2], … out of the box
  • Undefined filtered by defaultundefined props are removed from objects to unclutter test snahpsots
  • Rich selector syntax — target nested paths, array indices, slices, wildcards, and deep matches; with full TypeScript support
  • Zero config — works with your existing Vitest setup

Installation

npm i vitest-snap -D

Then register the matchers in your Vitest setup file:

vitest.setup.ts
import "vitest-snap";
vitest.config.ts
import { defineConfig } from "vitest/config";

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

Agent Skills

AI coding agents (Claude Code, Cursor, Copilot, etc.) can install vitest-snap skills to get accurate, pattern-aware guidance for this library:

npx @tanstack/intent@latest install vitest-snap

Last updated on

On this page