{"id":"2c99c34f5e58c439","repo":"vitest-dev/vitest","slug":"the-snapshot-state-for-filepath-is-not-found","errorCode":null,"errorMessage":"The snapshot state for '${filepath}' is not found. Did you call 'SnapshotClient.setup()?'","messagePattern":"The snapshot state for '(.+?)' is not found\\. Did you call 'SnapshotClient\\.setup\\(\\)\\?'","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/snapshot/src/client.ts","lineNumber":110,"sourceCode":"    const result = await state.pack()\n    this.snapshotStateMap.delete(filepath)\n    return result\n  }\n\n  skipTest(filepath: string, testName: string): void {\n    const state = this.getSnapshotState(filepath)\n    state.markSnapshotsAsCheckedForTest(testName)\n  }\n\n  clearTest(filepath: string, testId: string): void {\n    const state = this.getSnapshotState(filepath)\n    state.clearTest(testId)\n  }\n\n  getSnapshotState(filepath: string): SnapshotState {\n    const state = this.snapshotStateMap.get(filepath)\n    if (!state) {\n      throw new Error(\n        `The snapshot state for '${filepath}' is not found. Did you call 'SnapshotClient.setup()'?`,\n      )\n    }\n    return state\n  }\n\n  match(options: AssertOptions): MatchResult {\n    const {\n      filepath,\n      name,\n      testId = name,\n      message,\n      isInline = false,\n      properties,\n      inlineSnapshot,\n      error,\n      errorMessage,\n      rawSnapshot,","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/vitest-dev/vitest/blob/d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09/packages/snapshot/src/client.ts#L92-L128","documentation":"`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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nconst result = client.match({ filepath: '/a.test.ts', name: 'x', received: 1 })\n\n// after\nawait client.setup('/a.test.ts', { /* SnapshotStateOptions */ })\nconst result = client.match({ filepath: '/a.test.ts', name: 'x', received: 1 })","handlingStrategy":"validation","validationCode":"function assertSnapshotReady(client: SnapshotClient, filepath: string) {\n  if (!client.snapshotStateMap.has(filepath)) {\n    throw new Error(`No SnapshotState for '${filepath}'. Call await client.setup('${filepath}', options) first.`)\n  }\n}\n\n// usage before match/assert/finish:\nassertSnapshotReady(client, filepath)","typeGuard":null,"tryCatchPattern":"if (!client.snapshotStateMap.has(filepath)) {\n  await client.setup(filepath, options)\n}\nconst result = client.match({ filepath, name, received })","preventionTips":["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."],"tags":["snapshot","snapshot-client","lifecycle","validation"],"analyzedSha":"d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09","analyzedAt":"2026-08-03T20:23:56.861Z","schemaVersion":2}