oxc-project/oxc · warning

Expect requires at least {} argument{}

Error message

Expect requires at least {} argument{} 

What it means

Diagnostic from the shared jest/vitest `valid-expect` rule: `expect()` was called with fewer arguments than `minArgs` requires (default 1). `expect()` with no value cannot assert anything and usually means an incomplete edit or a spread/refactor gone wrong.

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. Pass the value under test: `expect(value)`.
  2. If you meant to assert calls happened, use `expect.hasAssertions()`/`expect.assertions(n)` on a separate line, not `expect()`.
  3. If a wrapper legitimately takes zero args, lower `minArgs` to 0 in the rule config.

Example fix

// before
expect();

// after
expect(getUser().name);
Defensive patterns

Strategy: validation

Validate before calling

const empty = /\bexpect\s*\(\s*\)/;
if (empty.test(src)) { console.error('expect() called with no argument'); process.exitCode = 1; }

Prevention

When it happens

Trigger: `(call_expr.arguments.len() as u32) < self.min_args` emits the formatted 'Expect requires at least N argument(s)' message. Concretely: `expect();`, `expect(...empty)`-style dynamic spreads, or `minArgs` raised in config while existing calls pass nothing.

Common situations: Half-written tests after a merge conflict or snippet paste; renaming a variable and accidentally deleting the argument; asserting on nothing while meaning `expect.hasAssertions()`.

Related errors


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