{"id":"269047bcf82a2826","repo":"jestjs/jest","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":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/expect/src/jestMatchersObject.ts","lineNumber":134,"sourceCode":"      Object.defineProperty(expect.not, key, {\n        configurable: true,\n        enumerable: true,\n        value: (...sample: [unknown, ...Array<unknown>]) =>\n          new CustomMatcher(true, ...sample),\n        writable: true,\n      });\n    }\n  }\n\n  Object.assign((globalThis as any)[JEST_MATCHERS_OBJECT].matchers, matchers);\n};\n\nexport const getCustomEqualityTesters = (): Array<Tester> =>\n  (globalThis as any)[JEST_MATCHERS_OBJECT].customEqualityTesters;\n\nexport const 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","sourceCodeStart":116,"sourceCodeEnd":145,"githubUrl":"https://github.com/jestjs/jest/blob/f49721c78e195558b40913977c9230f5b7f559d8/packages/expect/src/jestMatchersObject.ts#L116-L145","documentation":"addCustomEqualityTesters (the impl behind expect.addEqualityTesters) requires its argument be an array; it then spreads it into the global customEqualityTesters registry. A non-array would either be iterated incorrectly or silently merged, so Jest validates with Array.isArray and throws TypeError with getType() of the offending value.","triggerScenarios":"Calling expect.addEqualityTesters(myTester) with a single function instead of [myTester], passing null/undefined, or passing an object of testers by mistake.","commonSituations":"Reading the API as 'add a tester' (singular) and passing one function; copy-paste from a non-array source; migrating from a config where testers were keyed by name.","solutions":["Wrap testers in an array: expect.addEqualityTesters([myTester]).","Add multiple at once: expect.addEqualityTesters([testerA, testerB]).","Confirm each entry is a Tester function (signature (a, b, ctx) => boolean | undefined)."],"exampleFix":"// before\nexpect.addEqualityTesters(myDateTester); // single function, not an array\n\n// after\nexpect.addEqualityTesters([myDateTester]);","handlingStrategy":"type-guard","validationCode":"if (!Array.isArray(testers)) {\n  throw new TypeError('expect.addEqualityTesters needs an array of Tester functions');\n}\nexpect.addEqualityTesters(testers);","typeGuard":"function isTesterArray(x: unknown): x is Array<(a: unknown, b: unknown) => boolean | undefined> {\n  return Array.isArray(x) && x.every(t => typeof t === 'function');\n}","tryCatchPattern":"// addCustomEqualityTesters throws synchronously — wrap single testers in an array before calling","preventionTips":["Always pass an array literal: expect.addEqualityTesters([t]).","Type the parameter as Array<Tester> so TS rejects single functions.","Confirm each entry is a Tester-shaped function before adding."],"tags":["expect","equality-testers","type-error","validation"],"analyzedSha":"f49721c78e195558b40913977c9230f5b7f559d8","analyzedAt":"2026-08-03T20:16:28.571Z","schemaVersion":2}