{"record":{"id":"c085f4d899c1fe6e","repo":"oxc-project/oxc","slug":"expect-must-have-a-corresponding-matcher-call","errorCode":null,"errorMessage":"Expect must have a corresponding matcher call.","messagePattern":"Expect must have a corresponding matcher call\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","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 oxlint `jest/valid-expect` rule (source: crates/oxc_linter/src/rules/shared/jest_vitest/valid_expect.rs:23). This message ('Expect must have a corresponding matcher call.') fires when `expect(value)` is never chained to a matcher - the expression's value is discarded, so the assertion never runs and the test passes vacuously. The rule uses `ExpectError`-style helpers and the shared diagnostic builder in the source.","triggerScenarios":"`expect(value);` as a standalone expression statement, `const p = expect(x);` never followed by `.toBe/...`, or an expect chain broken by a stray semicolon or early return before the matcher. Detected via `collect_possible_jest_call_node` + `parse_expect_jest_fn_call` finding no matcher.","commonSituations":"Commenting out a matcher while debugging and forgetting to restore it; refactors that split the chain across lines; await-less `expect(promise).resolves...` typos where the chain got truncated; copy-paste that dropped the second line.","solutions":["Complete the assertion: `expect(value).toBe(expected)` or whichever matcher applies.","If the line was a debugging leftover, delete the bare `expect(...)`.","For promise assertions use the full chain: `await expect(fetchUser()).resolves.toMatchObject({ id: 1 })`.","Search for the pattern repo-wide with `rg 'expect\\([^)]*\\);\\s*$'` to catch other occurrences."],"exampleFix":"// before\nexpect(result.status);\n\n// after\nexpect(result.status).toBe('ok');","handlingStrategy":"validation","validationCode":"// rg -n \"expect\\([^)]*\\);\\s*$\" tests/ -t ts -t js  # bare expect statements","typeGuard":"// Guard for dynamic assertion helpers (JS):\nfunction assertHasMatcher(fn) {\n  const src = fn.toString();\n  return !/^\\s*expect\\([^)]*\\);\\s*$/m.test(src);\n}","tryCatchPattern":null,"preventionTips":["Never comment out just the matcher; comment the whole expect line","Write the full chain on one statement before splitting lines","Keep valid-expect enabled as an error so vacuous assertions fail lint"],"tags":["jest","vitest","oxlint","expect","assertion","vacuous-test"],"backgroundTag":"jest-valid-expect-matcher","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"}