vitest-dev/vitest · error · Error
The snapshot state for '${filepath}' is not found. Did you c
Error message
The snapshot state for '${filepath}' is not found. Did you call 'SnapshotClient.setup()?' What it means
`SnapshotClient` keeps a per-`filepath` `SnapshotState` created by `setup()`. Every other method (`match`, `assert`, `finish`, `skipTest`, `clearTest`) calls `getSnapshotState(filepath)`, which throws if no state was registered for that path — typically because `setup()` was skipped or `finish()` already deleted the entry.
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 d568f8ce37)
Solutions
- Always `await client.setup(filepath, options)` before any match/assert/finish for that file.
- Do not reuse a filepath after `finish()` without re-running `setup()`.
- Guard with `client.snapshotStateMap.has(filepath)` before calling state-dependent methods.
- Ensure the exact same `filepath` string is used in setup and subsequent calls.
Example fix
// before
const result = client.match({ filepath: '/a.test.ts', name: 'x', received: 1 })
// after
await client.setup('/a.test.ts', { /* SnapshotStateOptions */ })
const result = client.match({ filepath: '/a.test.ts', name: 'x', received: 1 }) Defensive patterns
Strategy: validation
Validate before calling
function assertSnapshotReady(client: SnapshotClient, filepath: string) {
if (!client.snapshotStateMap.has(filepath)) {
throw new Error(`No SnapshotState for '${filepath}'. Call await client.setup('${filepath}', options) first.`)
}
}
// usage before match/assert/finish:
assertSnapshotReady(client, filepath) Try / catch
if (!client.snapshotStateMap.has(filepath)) {
await client.setup(filepath, options)
}
const result = client.match({ filepath, name, received }) Prevention
- Always `await client.setup(filepath, options)` before any match/assert/finish for that file.
- Do not call `finish()` and then reuse the same filepath without re-setup.
- Use the exact same `filepath` string across setup/match/finish.
- Guard custom runners with `snapshotStateMap.has(filepath)` before state-dependent calls.
When it happens
Trigger: Calling `client.match({ filepath })`, `client.finish(filepath)`, `client.skipTest(filepath, ...)`, or `client.clearTest(filepath, ...)` before `await client.setup(filepath, options)`, or after a prior `finish()` removed the state.
Common situations: Programmatic snapshot use in a custom runner; calling assert before setup; double-finish; race where setup hasn't resolved before match runs; wrong filepath string between setup and match.
Related errors
- invalid snapshot serializer in ${file}. Must have a 'test' m
- bitLength is required
- Negative numbers are not supported
- Page "${sessionId}" not found in ${this.browserName} browser
- [vitest] The provider was closed.
AI-assisted analysis of vitest-dev/vitest@d568f8ce37 (2026-08-03).
Data as JSON: /data/errors/2c99c34f5e58c439.json.
Report an issue: GitHub.