{"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/f49721c78e195558b40913977c9230f5b7f559d8/packages/expect/src/index.ts#L89-L125","documentation":"expect() is variadic-checked: if you pass more than one positional argument it throws immediately. expect is designed to wrap a single actual value; extra arguments are almost always a typo (e.g., expect(a, b) where the user meant toBe called separately) and would otherwise silently drop the second arg.","triggerScenarios":"Calling expect(actual, extra), expect(a, b).toBe(...), or destructuring that yields two args. Passing rest.length > 0 is the trigger.","commonSituations":"Migrating from a different assertion library where multiple args are allowed; typos; copy-paste leaving an extra argument; tooling that injects arguments.","solutions":["Pass exactly one value: expect(actual).","Split chained assertions: expect(a).toBe(b) and expect(b).toBe(c) as separate lines.","If you have multiple values, assert each in its own expect() call or use toEqual with an array/object."],"exampleFix":"// before\nexpect(a, b).toBe(5);\n\n// after\nexpect(a).toBe(5);\nexpect(b).toBe(5);","handlingStrategy":"validation","validationCode":"if (arguments.length > 1) {\n  throw new Error('expect() takes exactly one argument');\n}\nexpect(actual);","typeGuard":"// n/a — variadic arity check, not a value-shape guard","tryCatchPattern":"// expect throws synchronously — fix the call site, do not catch at runtime","preventionTips":["Always call expect with a single actual value.","Use a linter rule or code review to flag expect(a, b) patterns.","Split multi-value assertions into separate expect calls."],"tags":["expect","api-misuse","validation"],"analyzedSha":"f49721c78e195558b40913977c9230f5b7f559d8","analyzedAt":"2026-08-03T20:16:28.571Z","schemaVersion":2}