{"record":{"id":"23f152ae1c9e5568","repo":"vitest-dev/vitest","slug":"custommessage-custommessage-mess","errorCode":null,"errorMessage":"(customMessage ? `${customMessage}: ` : '') + message()","messagePattern":"\\(customMessage \\? `(.+?): ` : ''\\) \\+ message\\(\\)","errorType":"exception","errorClass":"JestExtendError","httpStatus":null,"severity":"error","filePath":"packages/expect/src/jest-extend.ts","lineNumber":125,"sourceCode":"            const thenable = result as PromiseLike<SyncExpectationResult>\n            return thenable.then(({ pass, message, actual, expected, meta }) => {\n              if ((pass && isNot) || (!pass && !isNot)) {\n                const errorMessage = (customMessage ? `${customMessage}: ` : '') + message()\n                throw new JestExtendError(\n                  errorMessage,\n                  actual,\n                  expected,\n                  { assertionName: expectAssertionName, meta },\n                )\n              }\n            })\n          }\n\n          const { pass, message, actual, expected, meta } = result as SyncExpectationResult\n\n          if ((pass && isNot) || (!pass && !isNot)) {\n            const errorMessage = (customMessage ? `${customMessage}: ` : '') + message()\n            throw new JestExtendError(\n              errorMessage,\n              actual,\n              expected,\n              { assertionName: expectAssertionName, meta },\n            )\n          }\n        }\n\n        const softWrapper = wrapAssertion(utils, expectAssertionName, __VITEST_EXTEND_ASSERTION__)\n        utils.addMethod(\n          (globalThis as any)[JEST_MATCHERS_OBJECT].matchers,\n          expectAssertionName,\n          softWrapper,\n        )\n        utils.addMethod(\n          c.Assertion.prototype,\n          expectAssertionName,\n          softWrapper,","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/vitest-dev/vitest/blob/1fa9837ec26533512fdcad8baebf249771bd340a/packages/expect/src/jest-extend.ts#L107-L143","documentation":"Thrown by `jest.extend`-registered matchers when the matcher returns `pass: false` (or `pass: true` under `.not`). It builds the user-facing error by prepending any custom message and wrapping it in `JestExtendError` along with actual/expected/meta. This is the standard failure signal of a custom matcher.","triggerScenarios":"Registering a matcher via `expect.extend({...})` and asserting against values where the matcher's own logic reports `pass: false`; the custom matcher's expectation was not met.","commonSituations":"The matcher logic is correct but the input does not satisfy it (a real test failure); a bug in the matcher's `pass` computation; asymmetric matcher used with unexpected input.","solutions":["Treat as a normal assertion failure: inspect actual vs expected in the message and fix the SUT or the test.","If the matcher itself is wrong, correct its `pass`/`message` in the `expect.extend` definition.","Add a custom message via `expect(value, 'context').myMatcher(...)` to clarify failures."],"exampleFix":"// before: custom matcher reports failure\nexpect.extend({\n  toBeEven(received) {\n    return { pass: received % 2 === 0, message: () => 'expected even' }\n  },\n})\nexpect(3).toBeEven() // throws JestExtendError\n\n// after\nexpect(4).toBeEven()","handlingStrategy":"try-catch","validationCode":"try {\n  expect(value).myCustomMatcher(arg)\n} catch (e) {\n  // JestExtendError: inspect actual vs expected and adjust SUT or matcher\n}","typeGuard":null,"tryCatchPattern":"try {\n  expect(value, 'context').myMatcher(arg)\n} catch (err) {\n  if (!(err instanceof Error)) throw err\n  // report or soft-collect the failure\n  throw err\n}","preventionTips":["Verify the matcher's pass logic with unit tests on the matcher itself.","Provide a custom assertion message for clearer failures.","Return precise actual/expected so the error is actionable."],"tags":["expect","jest-extend","custom-matcher","assertion"],"backgroundTag":null,"analyzedSha":"1fa9837ec26533512fdcad8baebf249771bd340a","analyzedAt":"2026-08-11T16:11:39.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}