{"record":{"id":"af61b7795ae536a8","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/1fa9837ec26533512fdcad8baebf249771bd340a/packages/snapshot/src/client.ts#L92-L128","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","solutions":[],"exampleFix":"// before\nawait client.finish(filepath) // later\nclient.getSnapshotState(filepath)\n// after\nawait client.setup(filepath, {})\nclient.getSnapshotState(filepath)\nawait client.finish(filepath)","handlingStrategy":"validation","validationCode":"// Before any snapshot call, ensure state exists for the filepath\nif (!client.snapshotStateMap.has(filepath)) {\n  await client.setup(filepath, options)\n}\nclient.getSnapshotState(filepath)","typeGuard":"function hasSnapshotState(client: SnapshotClient, fp: string): boolean { return client.snapshotStateMap.has(fp) }","tryCatchPattern":null,"preventionTips":["Always pair setup(filepath) with finish(filepath)","Use identical filepath normalization across the lifecycle","Avoid calling finish before pending assertions"],"tags":["snapshot","lifecycle","setup","state"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}