{"record":{"id":"3dde1b707e806c1d","repo":"vitest-dev/vitest","slug":"expect-customequalitytesters-must-be-set-to-an-ar","errorCode":null,"errorMessage":"expect.customEqualityTesters: Must be set to an array of Testers. Was given \"${getType(newTesters)}\"","messagePattern":"expect\\.customEqualityTesters: Must be set to an array of Testers\\. Was given \"(.+?)\"","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/expect/src/jest-matcher-utils.ts","lineNumber":145,"sourceCode":"}\n\nexport function printWithType<T>(\n  name: string,\n  value: T,\n  print: (value: T) => string,\n): string {\n  const type = getType(value)\n  const hasType\n    = type !== 'null' && type !== 'undefined'\n      ? `${name} has type:  ${type}\\n`\n      : ''\n  const hasValue = `${name} has value: ${print(value)}`\n  return hasType + hasValue\n}\n\nexport function addCustomEqualityTesters(newTesters: Array<Tester>): void {\n  if (!Array.isArray(newTesters)) {\n    throw new TypeError(\n      `expect.customEqualityTesters: Must be set to an array of Testers. Was given \"${getType(\n        newTesters,\n      )}\"`,\n    )\n  }\n\n  (globalThis as any)[JEST_MATCHERS_OBJECT].customEqualityTesters.push(\n    ...newTesters,\n  )\n}\n\nexport function getCustomEqualityTesters(): Array<Tester> {\n  return (globalThis as any)[JEST_MATCHERS_OBJECT].customEqualityTesters\n}\n","sourceCodeStart":127,"sourceCodeEnd":160,"githubUrl":"https://github.com/vitest-dev/vitest/blob/1fa9837ec26533512fdcad8baebf249771bd340a/packages/expect/src/jest-matcher-utils.ts#L127-L160","documentation":"`addCustomEqualityTesters` (exposed as `expect.customEqualityTesters`) pushes testers onto a global array. If the caller passes something that is not an array, the call is rejected with a `TypeError` before any tester is registered. The message reports the runtime type via `getType`.","triggerScenarios":"Calling `expect.addCustomEqualityTesters(fn)` or `expect.customEqualityTesters = fn` with a single function instead of an array; passing `undefined`, an object, or a string.","commonSituations":"Following an older or incorrect example that passes a single tester; misreading the API signature; migrating from Jest where the array wrapping was implicit.","solutions":["Wrap the tester(s) in an array: `expect.addCustomEqualityTesters([myTester])`.","If you have multiple testers, pass them all in one array call.","Check the value is an array before calling (e.g. when testers come from a dynamic source)."],"exampleFix":"// before\nexpect.addCustomEqualityTesters(myTester)\n\n// after\nexpect.addCustomEqualityTesters([myTester])","handlingStrategy":"validation","validationCode":"if (!Array.isArray(testers)) {\n  throw new TypeError('expect.addCustomEqualityTesters requires an array')\n}\nexpect.addCustomEqualityTesters(testers)","typeGuard":"const isTesterArray = (v: unknown): v is Array<(a: unknown, b: unknown) => void | undefined> =>\n  Array.isArray(v)","tryCatchPattern":null,"preventionTips":["Always wrap testers in an array literal at the call site.","Validate dynamic tester sources before registering.","Follow the current API signature, not older single-argument examples."],"tags":["expect","custom-equality","type-error","jest-matcher-utils"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}