Skip to content

toMatchAgentSnapshot

toMatchAgentSnapshot(this, received, options?): object

Vitest custom matcher that compares a RunResult against a stored snapshot.

Uses deterministic serialization (sorted state keys, excluded keys removed) and delegates to Vitest’s built-in toMatchSnapshot() for the actual snapshot file management.

Register with expect.extend({ toMatchAgentSnapshot }) and use as:

expect(result).toMatchAgentSnapshot({ exclude: ['observe:duration'] })

any

Vitest matcher context

Pick<RunResult, "text" | "state"> & object

The RunResult to snapshot

SnapshotOptions

Optional snapshot options (exclude keys, etc.)

object

Matcher result with pass/fail and message

message: () => string

string

pass: boolean