oxc-project/oxc · warning

Expect has an unknown modifier.

Error message

Expect has an unknown modifier.

What it means

Diagnostic from the shared jest/vitest `valid-expect` rule (ExpectError::ModifierUnknown). It fires when the member between `expect()` and the matcher is not one of the known modifiers (`not`, `resolves`, `rejects`). Almost always a typo like `.resolvess` or `.Rejects`, which makes Jest/Vitest throw or silently misbehave at runtime.

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. Fix the spelling to a known modifier: `not`, `resolves`, or `rejects`.
  2. If you invented a modifier, replace it with the real API: use `await expect(p).resolves.toEqual(v)` instead of pseudo-modifiers like `.eventually`.
  3. If you truly extended expect with a custom modifier via expect.extend, either rename/wrap it as a matcher or silence the rule for that line with `// oxlint-disable-next-line valid-expect`.

Example fix

// before
expect(Promise.resolve(1)).resovlves.toBe(1);

// after
await expect(Promise.resolve(1)).resolves.toBe(1);
Defensive patterns

Strategy: validation

Validate before calling

const KNOWN = new Set(['not', 'resolves', 'rejects']);
// rough static check for unknown modifiers in an expect chain
const chain = 'expect(p).resovlves.toBe(1)';
const links = chain.slice(chain.indexOf('.') + 1).split('.').map(s => s.replace(/\(.*/, ''));
// last link is the matcher; anything before it that is not 'not' is a modifier
for (const l of links.slice(0, -1)) {
  if (!KNOWN.has(l)) console.warn(`unknown modifier: ${l}`);
}

Prevention

When it happens

Trigger: `parse_expect_jest_fn_call` sets ExpectError::ModifierUnknown when a chain link (other than the matcher) is not recognized as a known modifier. Examples: `expect(p).resovlves.toBe(1)`, `expect(p).fulfilled.toBe(1)`, or using a custom modifier name the rule does not know.

Common situations: Typos of `resolves`/`rejects` are the classic case; also developers inventing modifiers (`.eventually`, `.fulfilled`) from other assertion libraries (chai-as-promised), or shadowing modifier names after migrating a suite from another framework.

Related errors


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