oxc-project/oxc · warning

`{prefix}.assertions` expects a single argument of type numb

Error message

`{prefix}.assertions` expects a single argument of type number.

What it means

From the oxlint `prefer-expect-assertions` rule family: `expect.assertions(n)` declares exactly how many assertions the test must run, and its contract is a single numeric argument. Calling it with zero arguments or with several arguments violates that contract, so the linter reports it with this diagnostic telling you to pass exactly one number.

Source

Thrown at crates/oxc_linter/src/rules/shared/jest_vitest/prefer_expect_assertions.rs:174

```
"#;

fn expect_shadowed_by_parameter(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn(
        "`expect` is shadowed by a callback parameter and cannot be used for assertions.",
    )
    .with_help("Rename the parameter to avoid shadowing the global `expect`.")
    .with_label(span)
}

pub fn has_assertions_takes_no_arguments(span: Span, prefix: &str) -> OxcDiagnostic {
    OxcDiagnostic::warn(format!("`{prefix}.hasAssertions` expects no arguments."))
        .with_help(format!("Remove the arguments from `{prefix}.hasAssertions()`."))
        .with_label(span)
}

fn assertions_requires_one_argument(span: Span, prefix: &str) -> OxcDiagnostic {
    OxcDiagnostic::warn(format!("`{prefix}.assertions` expects a single argument of type number."))
        .with_help(format!("Pass a single numeric argument to `{prefix}.assertions()`."))
        .with_label(span)
}

fn assertions_requires_number_argument(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("This argument should be a number.")
        .with_help("Replace this argument with a numeric literal.")
        .with_label(span)
}

pub fn resolve_expect_local_name(ctx: &LintContext<'_>, sources: &[&str]) -> CompactStr {
    for entry in &ctx.module_record().import_entries {
        if entry.is_type {
            continue;
        }

        let source = entry.module_request.name();
        if !sources.contains(&source) {

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Count the assertions the test performs and pass that single number: `expect.assertions(3)`.
  2. If you cannot predict the count (loops, conditional assertions), use `expect.hasAssertions()` instead.

Example fix

// before
it('validates', () => {
  expect.assertions();
  expect(a).toBe(1);
  expect(b).toBe(2);
});

// after
it('validates', () => {
  expect.assertions(2);
  expect(a).toBe(1);
  expect(b).toBe(2);
});
Defensive patterns

Strategy: validation

Validate before calling

// .oxlintrc.json
{ "rules": { "jest/prefer-expect-assertions": "error" } }

npx oxlint tests/

Prevention

When it happens

Trigger: An `expect.assertions()` (or aliased `<prefix>.assertions()`) member call whose arguments array is empty, or whose length is greater than 1 — e.g. `expect.assertions()` or `expect.assertions(1, 2)`.

Common situations: Typo/deletion leaving empty parens; refactoring a call that previously took a variable that was moved; misunderstanding assertions() as variadic (e.g. passing a list of expected counts).

Related errors


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