jestjs/jest · error · Error

Expect takes at most one argument.

Error message

Expect takes at most one argument.

What it means

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.

Source

Thrown at packages/expect/src/index.ts:107

  };
};

const getPromiseMatcher = (name: string, matcher: RawMatcherFn) => {
  if (name === 'toThrow') {
    return createThrowMatcher(name, true);
  } else if (
    name === 'toThrowErrorMatchingSnapshot' ||
    name === 'toThrowErrorMatchingInlineSnapshot'
  ) {
    return createToThrowErrorMatchingSnapshotMatcher(matcher);
  }

  return null;
};

export const expect: Expect = (actual: any, ...rest: Array<any>) => {
  if (rest.length > 0) {
    throw new Error('Expect takes at most one argument.');
  }

  const allMatchers = getMatchers();
  const expectation: any = {
    not: {},
    rejects: {not: {}},
    resolves: {not: {}},
  };

  const err = new JestAssertionError();

  for (const name of Object.keys(allMatchers)) {
    const matcher = allMatchers[name];
    const promiseMatcher = getPromiseMatcher(name, matcher) || matcher;
    expectation[name] = makeThrowingMatcher(matcher, false, '', actual);
    expectation.not[name] = makeThrowingMatcher(matcher, true, '', actual);

    expectation.resolves[name] = makeResolveMatcher(

View on GitHub (pinned to f49721c78e)

Solutions

  1. Pass exactly one value: expect(actual).
  2. Split chained assertions: expect(a).toBe(b) and expect(b).toBe(c) as separate lines.
  3. If you have multiple values, assert each in its own expect() call or use toEqual with an array/object.

Example fix

// before
expect(a, b).toBe(5);

// after
expect(a).toBe(5);
expect(b).toBe(5);
Defensive patterns

Strategy: validation

Validate before calling

if (arguments.length > 1) {
  throw new Error('expect() takes exactly one argument');
}
expect(actual);

Type guard

// n/a — variadic arity check, not a value-shape guard

Try / catch

// expect throws synchronously — fix the call site, do not catch at runtime

Prevention

When it happens

Trigger: Calling expect(actual, extra), expect(a, b).toBe(...), or destructuring that yields two args. Passing rest.length > 0 is the trigger.

Common situations: Migrating from a different assertion library where multiple args are allowed; typos; copy-paste leaving an extra argument; tooling that injects arguments.

Related errors


AI-assisted analysis of jestjs/jest@f49721c78e (2026-08-03). Data as JSON: /data/errors/eee57e190f21307e.json. Report an issue: GitHub.