vitest-dev/vitest · error · Error
The snapshot state for
Error message
The snapshot state for '${filepath}' is not found. Did you call 'SnapshotClient.setup()'? What it means
SnapshotClient.getSnapshotState throws when no SnapshotState is registered for the given filepath. The state map is populated by SnapshotClient.setup(filepath) and removed by finish(filepath); any call in between (or before setup / after finish) on an unregistered path fails here.
Example fix
// before
await client.finish(filepath) // later
client.getSnapshotState(filepath)
// after
await client.setup(filepath, {})
client.getSnapshotState(filepath)
await client.finish(filepath) Defensive patterns
Strategy: validation
Validate before calling
// Before any snapshot call, ensure state exists for the filepath
if (!client.snapshotStateMap.has(filepath)) {
await client.setup(filepath, options)
}
client.getSnapshotState(filepath) Type guard
function hasSnapshotState(client: SnapshotClient, fp: string): boolean { return client.snapshotStateMap.has(fp) } Prevention
- Always pair setup(filepath) with finish(filepath)
- Use identical filepath normalization across the lifecycle
- Avoid calling finish before pending assertions
When it happens
Trigger: Calling snapshotClient.match/finish/skipTest/clearTest before setup(filepath); calling after finish(filepath) deleted the entry; passing a different filepath than the one used in setup (different normalization/casing).
Common situations: Using the SnapshotClient API directly (custom runner, REPL, standalone tooling) without the setup/teardown lifecycle; filepath mismatch between setup and assertion due to path normalization; calling finish twice; teardown ordering bug in a custom environment.
Related errors
- Snapshot cannot be used outside of test
- aria adapter expects an Element
- Assertion name is not set. This is a bug in Vitest. Please…
- Browser is not initialized
- Browser provider is not defined for the project
AI-assisted analysis of vitest-dev/vitest@1fa9837ec2 (2026-08-11).
Data as JSON: /api/errors/af61b7795ae536a8.
Report an issue: GitHub.
Appendix: source
Thrown at packages/snapshot/src/client.ts:110
const result = await state.pack()
this.snapshotStateMap.delete(filepath)
return result
}
skipTest(filepath: string, testName: string): void {
const state = this.getSnapshotState(filepath)
state.markSnapshotsAsCheckedForTest(testName)
}
clearTest(filepath: string, testId: string): void {
const state = this.getSnapshotState(filepath)
state.clearTest(testId)
}
getSnapshotState(filepath: string): SnapshotState {
const state = this.snapshotStateMap.get(filepath)
if (!state) {
throw new Error(
`The snapshot state for '${filepath}' is not found. Did you call 'SnapshotClient.setup()'?`,
)
}
return state
}
match(options: AssertOptions): MatchResult {
const {
filepath,
name,
testId = name,
message,
isInline = false,
properties,
inlineSnapshot,
error,
errorMessage,
rawSnapshot,View on GitHub (pinned to 1fa9837ec2)