{"record":{"id":"eee57e190f21307e","repo":"jestjs/jest","slug":"expect-takes-at-most-one-argument","errorCode":null,"errorMessage":"Expect takes at most one argument.","messagePattern":"Expect takes at most one argument\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/expect/src/index.ts","lineNumber":107,"sourceCode":"  };\n};\n\nconst getPromiseMatcher = (name: string, matcher: RawMatcherFn) => {\n  if (name === 'toThrow') {\n    return createThrowMatcher(name, true);\n  } else if (\n    name === 'toThrowErrorMatchingSnapshot' ||\n    name === 'toThrowErrorMatchingInlineSnapshot'\n  ) {\n    return createToThrowErrorMatchingSnapshotMatcher(matcher);\n  }\n\n  return null;\n};\n\nexport const expect: Expect = (actual: any, ...rest: Array<any>) => {\n  if (rest.length > 0) {\n    throw new Error('Expect takes at most one argument.');\n  }\n\n  const allMatchers = getMatchers();\n  const expectation: any = {\n    not: {},\n    rejects: {not: {}},\n    resolves: {not: {}},\n  };\n\n  const err = new JestAssertionError();\n\n  for (const name of Object.keys(allMatchers)) {\n    const matcher = allMatchers[name];\n    const promiseMatcher = getPromiseMatcher(name, matcher) || matcher;\n    expectation[name] = makeThrowingMatcher(matcher, false, '', actual);\n    expectation.not[name] = makeThrowingMatcher(matcher, true, '', actual);\n\n    expectation.resolves[name] = makeResolveMatcher(","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/jestjs/jest/blob/8e6d128e4a278059ecddecaa97400b04c8ae5fd9/packages/expect/src/index.ts#L89-L125","documentation":"expect() accepts exactly one argument — the actual value under test. Passing extra arguments throws an Error because there is no defined meaning for them and it almost always indicates a typo (e.g. expecting `expect(a).toBe(b)` but writing `expect(a, b).toBe()`). The check keeps assertions unambiguous.","triggerScenarios":"Calling `expect(value, extra)` with more than one argument. Most often a misplaced matcher: `expect(a, b)` instead of `expect(a).toEqual(b)`, or a stray comma/comma operator.","commonSituations":"Confusing expect's signature with chai-style `assert.equal(a, b)`; copy-paste errors; an extra argument slipped in by a refactor.","solutions":["Use the matcher chain: `expect(actual).toEqual(expected)` instead of `expect(actual, expected)`.","Remove any extra arguments to expect() so only the actual value is passed.","If you intended to pass options, check the matcher API — options go on the matcher, not on expect()."],"exampleFix":"// before\nexpect(result, expected).toBeTruthy(); // two args\n\n// after\nexpect(result).toEqual(expected);","handlingStrategy":"validation","validationCode":"// Wrap expect in dev/test helpers to surface misuse at the call site.\nfunction expectOne(actual) {\n  if (arguments.length > 1) {\n    throw new Error('expect() takes one argument; use a matcher for the comparison.');\n  }\n  return expect(actual);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use the matcher chain (expect(a).toEqual(b)) instead of expect(a, b).","Enable a linter rule (e.g. eslint-plugin-jest) to catch malformed expect calls.","Review copy-pasted assertions for stray arguments."],"tags":["expect","api-misuse","assertion"],"backgroundTag":null,"analyzedSha":"8e6d128e4a278059ecddecaa97400b04c8ae5fd9","analyzedAt":"2026-08-10T18:11:27.960Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}