{"record":{"id":"3ced69e6e525414d","repo":"jestjs/jest","slug":"this-matcher-must-not-have-an-expected-argument","errorCode":null,"errorMessage":"this matcher must not have an expected argument","messagePattern":"this matcher must not have an expected argument","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/jest-matcher-utils/src/index.ts","lineNumber":163,"sourceCode":"): 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 const ensureNoExpected = (\n  expected: unknown,\n  matcherName: string,\n  options?: MatcherHintOptions,\n): void => {\n  if (expected !== undefined) {\n    // Prepend maybe not only for backward compatibility.\n    const matcherString = (options ? '' : '[.not]') + matcherName;\n    throw new Error(\n      matcherErrorMessage(\n        matcherHint(matcherString, undefined, '', options),\n        // Because expected is omitted in hint above,\n        // expected is black instead of green in message below.\n        'this matcher must not have an expected argument',\n        printWithType('Expected', expected, printExpected),\n      ),\n    );\n  }\n};\n\n/**\n * Ensures that `actual` is of type `number | bigint`\n */\nexport const ensureActualIsNumber = (\n  actual: unknown,\n  matcherName: string,\n  options?: MatcherHintOptions,","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/jestjs/jest/blob/8e6d128e4a278059ecddecaa97400b04c8ae5fd9/packages/jest-matcher-utils/src/index.ts#L145-L181","documentation":"Thrown by ensureNoExpected in jest-matcher-utils when a matcher that takes no expected value is invoked with one (index.ts:160-172). Matchers like toBeNull, toBeTruthy, toBeDefined call ensureNoExpected; supplying an argument is a usage error because those matchers compare against a fixed state, not a user-provided expected value.","triggerScenarios":"expect(x).toBeNull(null), expect(x).toBeTruthy(true), expect(x).toBeDefined(undefined), expect(x).toBeNaN(NaN), or writing a custom matcher that calls ensureNoExpected and then passing an argument from the test.","commonSituations":"Auto-completing matcher calls with a value out of habit; porting tests from expect(x).toBe(null) to toBeNull but keeping the argument; custom matchers that misuse ensureNoExpected; refactoring that left a stray argument.","solutions":["Remove the expected argument: expect(x).toBeNull().","If you meant to compare equality, use the right matcher: expect(x).toBe(null) for exact equality.","For custom matchers, only call ensureNoExpected when the matcher truly takes no expected value, and document it.","Add an ESLint rule banning arguments on zero-arg matchers (eslint-plugin-jest)."],"exampleFix":"// before\nexpect(user).toBeNull(null);\n// after\nexpect(user).toBeNull();","handlingStrategy":"validation","validationCode":"// custom matcher authors\nif (expected !== undefined) {\n  throw new Error('This matcher must not receive an expected argument');\n}\n// test authors: just omit the argument\nexpect(x).toBeNull();","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use zero-arg matchers (toBeNull, toBeTruthy) without arguments.","Switch to toBe(expected) for equality checks.","Lint with eslint-plugin-jest to catch stray arguments."],"tags":["jest","matcher","assertion","api-misuse","expected-argument"],"backgroundTag":null,"analyzedSha":"8e6d128e4a278059ecddecaa97400b04c8ae5fd9","analyzedAt":"2026-08-10T18:11:27.960Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}