{"id":"10a0f2e34b7f4c89","repo":"jestjs/jest","slug":"custom-snapshot-resolver-must-implement-a-propn","errorCode":null,"errorMessage":"Custom snapshot resolver must implement a `${propName}` as a ${requiredType}.\nDocumentation: https://jestjs.io/docs/configuration#snapshotresolver-string","messagePattern":"Custom snapshot resolver must implement a `(.+?)` as a (.+?)\\.\nDocumentation: https://jestjs\\.io/docs/configuration#snapshotresolver-string","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/jest-snapshot/src/SnapshotResolver.ts","lineNumber":97,"sourceCode":"  };\n}\n\nasync function createCustomSnapshotResolver(\n  snapshotResolverPath: string,\n  localRequire: LocalRequire,\n): Promise<SnapshotResolver> {\n  const custom: SnapshotResolver = interopRequireDefault(\n    await localRequire(snapshotResolverPath),\n  ).default;\n\n  const keys: Array<[keyof SnapshotResolver, string]> = [\n    ['resolveSnapshotPath', 'function'],\n    ['resolveTestPath', 'function'],\n    ['testPathForConsistencyCheck', 'string'],\n  ];\n  for (const [propName, requiredType] of keys) {\n    if (typeof custom[propName] !== requiredType) {\n      throw new TypeError(mustImplement(propName, requiredType));\n    }\n  }\n\n  const customResolver: SnapshotResolver = {\n    resolveSnapshotPath: (testPath: string) =>\n      custom.resolveSnapshotPath(testPath, DOT_EXTENSION),\n    resolveTestPath: (snapshotPath: string) =>\n      custom.resolveTestPath(snapshotPath, DOT_EXTENSION),\n    testPathForConsistencyCheck: custom.testPathForConsistencyCheck,\n  };\n\n  verifyConsistentTransformations(customResolver);\n\n  return customResolver;\n}\n\nfunction mustImplement(propName: string, requiredType: string) {\n  return `${chalk.bold(","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/jestjs/jest/blob/f49721c78e195558b40913977c9230f5b7f559d8/packages/jest-snapshot/src/SnapshotResolver.ts#L79-L115","documentation":"Thrown by `createCustomSnapshotResolver` (SnapshotResolver.ts:90-99) when the module pointed to by config `snapshotResolver` is missing one of the three required exports or has the wrong type. The contract requires `resolveSnapshotPath` (function), `resolveTestPath` (function), and `testPathForConsistencyCheck` (string). A `TypeError` is thrown naming the offending property.","triggerScenarios":"Config `snapshotResolver: './snapshotResolver.js'` where the file exports only `resolveSnapshotPath`, or exports `testPathForConsistencyCheck` as a function instead of a string, or has a typo in the export name.","commonSituations":"Copy-pasting a partial resolver from docs. Default-vs-named export confusion (`export default` vs `module.exports =`). Renaming an export without updating all three.","solutions":["Ensure the resolver module exports all three with correct types: two functions and one string literal path.","Use `module.exports = { resolveSnapshotPath, resolveTestPath, testPathForConsistencyCheck }` (CJS) or equivalent named ESM exports.","Double-check `testPathForConsistencyCheck` is a string path (commonly `path.resolve(__dirname, 'example.test.js')`), not a function."],"exampleFix":"// before — missing resolveTestPath\nmodule.exports = {\n  resolveSnapshotPath: testPath => testPath.replace('.test.', '.snap.'),\n  testPathForConsistencyCheck: 'example.test.js',\n};\n\n// after — all three exports, correct types\nmodule.exports = {\n  resolveSnapshotPath: testPath => testPath.replace('.test.', '.snap.'),\n  resolveTestPath: snapshotPath => snapshotPath.replace('.snap.', '.test.'),\n  testPathForConsistencyCheck: 'example.test.js',\n};","handlingStrategy":"validation","validationCode":"const r = require('./snapshotResolver');\nconst checks: Array<[keyof typeof r, string]> = [\n  ['resolveSnapshotPath', 'function'],\n  ['resolveTestPath', 'function'],\n  ['testPathForConsistencyCheck', 'string'],\n];\nfor (const [k, t] of checks) {\n  if (typeof r[k] !== t) {\n    throw new Error(`Resolver missing ${k} as ${t}`);\n  }\n}","typeGuard":"function isSnapshotResolver(v: unknown): v is { resolveSnapshotPath: Function; resolveTestPath: Function; testPathForConsistencyCheck: string } {\n  return (\n    !!v &&\n    typeof (v as any).resolveSnapshotPath === 'function' &&\n    typeof (v as any).resolveTestPath === 'function' &&\n    typeof (v as any).testPathForConsistencyCheck === 'string'\n  );\n}","tryCatchPattern":null,"preventionTips":["Add a unit test for your resolver module that asserts all three exports and their types.","Use TypeScript types from @jest/snapshot where available to catch shape errors at compile time.","Keep the resolver file small and dedicated to the three exports."],"tags":["snapshot-resolver","config","type-error"],"analyzedSha":"f49721c78e195558b40913977c9230f5b7f559d8","analyzedAt":"2026-08-03T20:16:28.571Z","schemaVersion":2}