{"record":{"id":"f5146164f061fe2a","repo":"oxc-project/oxc","slug":"expect-has-an-unknown-modifier","errorCode":null,"errorMessage":"Expect has an unknown modifier.","messagePattern":"Expect has an unknown modifier\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/shared/jest_vitest/valid_expect.rs","lineNumber":23,"sourceCode":"use oxc_semantic::ScopeId;\nuse oxc_span::{GetSpan, Span};\nuse rustc_hash::FxHashSet;\nuse schemars::JsonSchema;\n\nuse crate::{\n    AstNode,\n    context::LintContext,\n    utils::{\n        ExpectError, PossibleJestNode, collect_possible_jest_call_node, parse_expect_jest_fn_call,\n    },\n};\n\nfn valid_expect_diagnostic<S: Into<Cow<'static, str>>>(\n    x1: S,\n    x2: &'static str,\n    span3: Span,\n) -> OxcDiagnostic {\n    OxcDiagnostic::warn(x1).with_help(x2).with_label(span3)\n}\n\npub const DOCUMENTATION: &str = r\"### What it does\n\nChecks that `expect()` is called correctly.\n\n### Why is this bad?\n\n`expect()` is a function that is used to assert values in tests.\nIt should be called with a single argument, which is the value to be tested.\nIf you call `expect()` with no arguments, or with more than one argument, it will not work as expected.\n\n### Examples\n\nExamples of **incorrect** code for this rule:\n```javascript\nexpect();\nexpect('something');","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/shared/jest_vitest/valid_expect.rs#L5-L41","documentation":"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.","triggerScenarios":"`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.","commonSituations":"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.","solutions":["Fix the spelling to a known modifier: `not`, `resolves`, or `rejects`.","If you invented a modifier, replace it with the real API: use `await expect(p).resolves.toEqual(v)` instead of pseudo-modifiers like `.eventually`.","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`."],"exampleFix":"// before\nexpect(Promise.resolve(1)).resovlves.toBe(1);\n\n// after\nawait expect(Promise.resolve(1)).resolves.toBe(1);","handlingStrategy":"validation","validationCode":"const KNOWN = new Set(['not', 'resolves', 'rejects']);\n// rough static check for unknown modifiers in an expect chain\nconst chain = 'expect(p).resovlves.toBe(1)';\nconst links = chain.slice(chain.indexOf('.') + 1).split('.').map(s => s.replace(/\\(.*/, ''));\n// last link is the matcher; anything before it that is not 'not' is a modifier\nfor (const l of links.slice(0, -1)) {\n  if (!KNOWN.has(l)) console.warn(`unknown modifier: ${l}`);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Memorize the only built-in modifiers: `not`, `resolves`, `rejects`.","Let the editor autocomplete member expressions on the expect chain instead of typing modifiers by hand.","When coming from chai-as-promised, remember `.eventually` does not exist in jest/vitest — use `resolves`/`rejects`."],"tags":["jest","vitest","oxlint","testing","typo","promise"],"backgroundTag":"jest-expect-unknown-modifier","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}