jestjs/jest · error · TypeError

Custom snapshot resolver must implement a `${propName}` as a

Error message

Custom snapshot resolver must implement a `${propName}` as a ${requiredType}.
Documentation: https://jestjs.io/docs/configuration#snapshotresolver-string

What it means

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.

Source

Thrown at packages/jest-snapshot/src/SnapshotResolver.ts:97

  };
}

async function createCustomSnapshotResolver(
  snapshotResolverPath: string,
  localRequire: LocalRequire,
): Promise<SnapshotResolver> {
  const custom: SnapshotResolver = interopRequireDefault(
    await localRequire(snapshotResolverPath),
  ).default;

  const keys: Array<[keyof SnapshotResolver, string]> = [
    ['resolveSnapshotPath', 'function'],
    ['resolveTestPath', 'function'],
    ['testPathForConsistencyCheck', 'string'],
  ];
  for (const [propName, requiredType] of keys) {
    if (typeof custom[propName] !== requiredType) {
      throw new TypeError(mustImplement(propName, requiredType));
    }
  }

  const customResolver: SnapshotResolver = {
    resolveSnapshotPath: (testPath: string) =>
      custom.resolveSnapshotPath(testPath, DOT_EXTENSION),
    resolveTestPath: (snapshotPath: string) =>
      custom.resolveTestPath(snapshotPath, DOT_EXTENSION),
    testPathForConsistencyCheck: custom.testPathForConsistencyCheck,
  };

  verifyConsistentTransformations(customResolver);

  return customResolver;
}

function mustImplement(propName: string, requiredType: string) {
  return `${chalk.bold(

View on GitHub (pinned to f49721c78e)

Solutions

  1. Ensure the resolver module exports all three with correct types: two functions and one string literal path.
  2. Use `module.exports = { resolveSnapshotPath, resolveTestPath, testPathForConsistencyCheck }` (CJS) or equivalent named ESM exports.
  3. Double-check `testPathForConsistencyCheck` is a string path (commonly `path.resolve(__dirname, 'example.test.js')`), not a function.

Example fix

// before — missing resolveTestPath
module.exports = {
  resolveSnapshotPath: testPath => testPath.replace('.test.', '.snap.'),
  testPathForConsistencyCheck: 'example.test.js',
};

// after — all three exports, correct types
module.exports = {
  resolveSnapshotPath: testPath => testPath.replace('.test.', '.snap.'),
  resolveTestPath: snapshotPath => snapshotPath.replace('.snap.', '.test.'),
  testPathForConsistencyCheck: 'example.test.js',
};
Defensive patterns

Strategy: validation

Validate before calling

const r = require('./snapshotResolver');
const checks: Array<[keyof typeof r, string]> = [
  ['resolveSnapshotPath', 'function'],
  ['resolveTestPath', 'function'],
  ['testPathForConsistencyCheck', 'string'],
];
for (const [k, t] of checks) {
  if (typeof r[k] !== t) {
    throw new Error(`Resolver missing ${k} as ${t}`);
  }
}

Type guard

function isSnapshotResolver(v: unknown): v is { resolveSnapshotPath: Function; resolveTestPath: Function; testPathForConsistencyCheck: string } {
  return (
    !!v &&
    typeof (v as any).resolveSnapshotPath === 'function' &&
    typeof (v as any).resolveTestPath === 'function' &&
    typeof (v as any).testPathForConsistencyCheck === 'string'
  );
}

Prevention

When it happens

Trigger: 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.

Common situations: Copy-pasting a partial resolver from docs. Default-vs-named export confusion (`export default` vs `module.exports =`). Renaming an export without updating all three.

Related errors


AI-assisted analysis of jestjs/jest@f49721c78e (2026-08-03). Data as JSON: /data/errors/10a0f2e34b7f4c89.json. Report an issue: GitHub.