{"record":{"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/8e6d128e4a278059ecddecaa97400b04c8ae5fd9/packages/expect/src/jestMatchersObject.ts#L116-L145","documentation":"expect.addEqualityTesters (which sets customEqualityTesters) requires an array of Tester functions used to extend the equals algorithm. addCustomEqualityTesters throws a TypeError if the argument is not an array, because it spreads the testers into the global registry and a non-array would either spread incorrectly or push the wrong shape. The message reports the actual type via getType.","triggerScenarios":"Calling `expect.addEqualityTesters(value)` where value is not an array — e.g. a single tester function passed without wrapping in [], or an object/map of testers.","commonSituations":"Passing a single function instead of an array of functions; passing an object keyed by name expecting it to be merged; refactoring from a previous API that accepted a single tester.","solutions":["Wrap testers in an array: `expect.addEqualityTesters([myTester])`.","If you have multiple testers, pass them all in one array: `expect.addEqualityTesters([testerA, testerB])`.","Confirm each entry is a Tester function (signature (a, b, customTesters) => boolean | undefined)."],"exampleFix":"// before\nexpect.addEqualityTesters(myDateTester); // single function, not an array\n\n// after\nexpect.addEqualityTesters([myDateTester]);","handlingStrategy":"type-guard","validationCode":"function addTestersSafe(testers) {\n  if (!Array.isArray(testers)) {\n    throw new TypeError('expect.addEqualityTesters requires an array of Tester functions');\n  }\n  expect.addEqualityTesters(testers);\n}","typeGuard":"function isTesterArray(v: unknown): v is Array<(a: unknown, b: unknown) => boolean | undefined> {\n  return Array.isArray(v) && v.every(t => typeof t === 'function');\n}","tryCatchPattern":null,"preventionTips":["Always pass an array literal to expect.addEqualityTesters, even for a single tester.","Confirm each tester is a function with the Tester signature.","Register testers once in setupFilesAfterEach/setupFiles, not per-test."],"tags":["expect","equality-testers","typeerror","api-misuse"],"backgroundTag":null,"analyzedSha":"8e6d128e4a278059ecddecaa97400b04c8ae5fd9","analyzedAt":"2026-08-10T18:11:27.960Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}