{"id":"7eee66f32aba52f7","repo":"vitest-dev/vitest","slug":"raw-snapshot-is-required","errorCode":null,"errorMessage":"Raw snapshot is required","messagePattern":"Raw snapshot is required","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/snapshot/src/client.ts","lineNumber":348,"sourceCode":"      received: stableResult.rendered,\n      expectedSnapshot,\n      matchResult,\n      isInline,\n      error,\n      assertionName: options.assertionName,\n    })\n\n    return {\n      pass,\n      message: () => `Snapshot \\`${key}\\` mismatched`,\n      actual: actual?.trim(),\n      expected: expected?.trim(),\n    }\n  }\n\n  async assertRaw(options: AssertOptions): Promise<void> {\n    if (!options.rawSnapshot) {\n      throw new Error('Raw snapshot is required')\n    }\n\n    const { filepath, rawSnapshot } = options\n\n    if (rawSnapshot.content == null) {\n      if (!filepath) {\n        throw new Error('Snapshot cannot be used outside of test')\n      }\n\n      const snapshotState = this.getSnapshotState(filepath)\n\n      // save the filepath, so it don't lose even if the await make it out-of-context\n      options.filepath ||= filepath\n      // resolve and read the raw snapshot file\n      rawSnapshot.file = await snapshotState.environment.resolveRawPath(\n        filepath,\n        rawSnapshot.file,\n      )","sourceCodeStart":330,"sourceCodeEnd":366,"githubUrl":"https://github.com/vitest-dev/vitest/blob/d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09/packages/snapshot/src/client.ts#L330-L366","documentation":"Thrown by SnapshotClient.assertRaw() when options.rawSnapshot is undefined. Raw snapshots (toMatchSnapshot with a { raw: true } option or toMatchRawSnapshot) require a RawSnapshotInfo object so Vitest knows which file to write the unformatted bytes/string to. Calling assertRaw without it is a programmer error — there is no raw target to write to.","triggerScenarios":"Calling client.assertRaw({...}) without a rawSnapshot field; using a custom matcher that routes to assertRaw but forgets to build the RawSnapshotInfo; calling expect(value).toMatchRawSnapshot() through a shim that drops the raw option.","commonSituations":"Writing a custom expect.extend matcher around raw snapshots; migrating from toMatchSnapshot to toMatchRawSnapshot and forgetting the raw marker; third-party plugins that wrap the snapshot client incorrectly.","solutions":["Pass options.rawSnapshot = { file: '<path>', content: undefined } (or let Vitest fill content) when calling assertRaw.","Use expect(value).toMatchRawSnapshot() directly instead of a custom wrapper so Vitest builds the RawSnapshotInfo for you.","If you only need a normal snapshot, call client.assert(options) instead of client.assertRaw(options).","Audit custom matchers to ensure they forward the rawSnapshot option through."],"exampleFix":"// before\nawait client.assertRaw({ filepath, received })\n\n// after\nawait client.assertRaw({ filepath, received, rawSnapshot: { file: filepath + '.raw' } })","handlingStrategy":"validation","validationCode":"function isRawSnapshotInfo(v: unknown): v is { file: string; content?: string } {\n  return typeof v === 'object' && v !== null && typeof (v as any).file === 'string'\n}\nif (!isRawSnapshotInfo(options.rawSnapshot)) {\n  throw new TypeError('rawSnapshot must be { file: string, content?: string }')\n}","typeGuard":"const isRawSnapshotInfo = (v: unknown): v is { file: string; content?: string } =>\n  typeof v === 'object' && v !== null && typeof (v as any).file === 'string'","tryCatchPattern":null,"preventionTips":["Prefer the public expect(value).toMatchRawSnapshot() API which constructs RawSnapshotInfo for you.","In custom matchers, build the rawSnapshot object before calling assertRaw and validate its shape.","Document the required rawSnapshot shape on any wrapper you expose."],"tags":["snapshot","raw-snapshot","api-misuse"],"analyzedSha":"d568f8ce3739b532d5bf2c1ee1e45e8a8a473d09","analyzedAt":"2026-08-03T20:23:56.861Z","schemaVersion":2}