{"record":{"id":"26fb1a45ae023e6e","repo":"vitest-dev/vitest","slug":"unrecognized-comparator-comparator","errorCode":null,"errorMessage":"Unrecognized comparator ${comparator}","messagePattern":"Unrecognized comparator (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/browser/src/node/commands/screenshotMatcher/comparators/index.ts","lineNumber":34,"sourceCode":"  context: BrowserCommandContext,\n): Comparator<ScreenshotComparatorRegistry[ComparatorName]> {\n  if (comparator in comparators) {\n    return comparators[comparator]\n  }\n\n  const customComparators = context\n    .project\n    .config\n    .browser\n    .expect\n    ?.toMatchScreenshot\n    ?.comparators\n\n  if (customComparators && comparator in customComparators) {\n    return customComparators[comparator]\n  }\n\n  throw new Error(`Unrecognized comparator ${comparator}`)\n}\n\nexport type AnyComparator = Comparator<ScreenshotComparatorRegistry[keyof ScreenshotComparatorRegistry]>\n","sourceCodeStart":16,"sourceCodeEnd":38,"githubUrl":"https://github.com/vitest-dev/vitest/blob/1fa9837ec26533512fdcad8baebf249771bd340a/packages/browser/src/node/commands/screenshotMatcher/comparators/index.ts#L16-L38","documentation":"Thrown by `getComparator` when the requested comparator name is neither the built-in `'pixelmatch'` nor a key in the user-provided `browser.expect.toMatchScreenshot.comparators` config map. The comparator is the function that diffs the decoded reference against the captured screenshot; an unknown name means no diffing strategy is available, so the matcher aborts during option resolution.","triggerScenarios":"Passing `comparator: 'odiff'` (or any name) without registering it in config; misspelling `'pixelmatch'`; referencing a custom comparator key that was never added to `browser.expect.toMatchScreenshot.comparators`.","commonSituations":"Copy-pasting a comparator name from docs/another tool (e.g. `odiff`) without installing/registering it; renaming a custom comparator in code but not in config; case mismatch in the key.","solutions":["Use the default `'pixelmatch'` comparator (omit the `comparator` option).","Register a custom comparator under `test.browser.expect.toMatchScreenshot.comparators` in the Vitest config and reference its exact key.","Check spelling and case of the comparator name against the config keys."],"exampleFix":"// vitest.config.ts\n// before: comparator: 'odiff' referenced but not registered\n\n// after\nexport default defineConfig({\n  test: {\n    browser: {\n      expect: {\n        toMatchScreenshot: {\n          comparators: { odiff: myOdiffComparator },\n        },\n      },\n    },\n  },\n})","handlingStrategy":"validation","validationCode":"const BUILTIN = new Set(['pixelmatch'])\nconst custom = new Set(Object.keys(config.test?.browser?.expect?.toMatchScreenshot?.comparators ?? {}))\nif (!BUILTIN.has(name) && !custom.has(name)) {\n  throw new Error(`Unknown comparator '${name}'. Built-in: pixelmatch. Registered: ${[...custom].join(', ')}`)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Omit the `comparator` option to use the default `pixelmatch`.","Register custom comparators in `test.browser.expect.toMatchScreenshot.comparators` before referencing them.","Double-check comparator name spelling and case."],"tags":["screenshot","comparator","config","browser","visual-regression"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}