oxc-project/oxc · warning

Expect takes at most {} argument{}

Error message

Expect takes at most {} argument{} 

What it means

Diagnostic from the shared jest/vitest `valid-expect` rule: the `expect()` call itself was passed more arguments than `maxArgs` allows (default 1, per ValidExpectConfig). Extra arguments are silently ignored by Jest/Vitest, so a custom-message second argument does nothing and signals a mistake.

Source

Thrown at crates/oxc_linter/src/rules/shared/jest_vitest/valid_expect.rs:23

use oxc_semantic::ScopeId;
use oxc_span::{GetSpan, Span};
use rustc_hash::FxHashSet;
use schemars::JsonSchema;

use crate::{
    AstNode,
    context::LintContext,
    utils::{
        ExpectError, PossibleJestNode, collect_possible_jest_call_node, parse_expect_jest_fn_call,
    },
};

fn valid_expect_diagnostic<S: Into<Cow<'static, str>>>(
    x1: S,
    x2: &'static str,
    span3: Span,
) -> OxcDiagnostic {
    OxcDiagnostic::warn(x1).with_help(x2).with_label(span3)
}

pub const DOCUMENTATION: &str = r"### What it does

Checks that `expect()` is called correctly.

### Why is this bad?

`expect()` is a function that is used to assert values in tests.
It should be called with a single argument, which is the value to be tested.
If you call `expect()` with no arguments, or with more than one argument, it will not work as expected.

### Examples

Examples of **incorrect** code for this rule:
```javascript
expect();
expect('something');

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Reduce the call to the allowed argument count: `expect(actual)`.
  2. Move the intended custom message into the matcher (`toBe(expected, 'message')` in vitest) or an explicit `ctx.assert`/error message.
  3. If two arguments are intentional, raise `maxArgs` in the rule's config: `{ "rules": { "valid-expect": ["error", { "maxArgs": 2 }] } }`.

Example fix

// before
expect(result, 'result should be truthy');

// after
expect(result).toBeDefined();
Defensive patterns

Strategy: validation

Validate before calling

// reject multi-argument expect() calls before commit
const multi = /\bexpect\s*\([^(),]+\s*,/; // crude: expect(x, ...)
if (multi.test(src)) { console.error('expect() called with more than one argument'); process.exitCode = 1; }

Prevention

When it happens

Trigger: `(call_expr.arguments.len() as u32) > self.max_args && !allow_message_arg` fires the formatted 'Expect takes at most N argument(s)' message. Concretely: `expect(a, b)`, `expect(a, 'custom message')` when the string-message escape hatch is off, or `maxArgs` lowered in `.oxlintrc.json` while code still passes two values.

Common situations: Developers porting chai/QUnit habits (message as second argument), or configuring `minArgs`/`maxArgs` for a wrapped expect without updating call sites.

Related errors


AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20). Data as JSON: /api/errors/1086bfc9003c4542. Report an issue: GitHub.