{"record":{"id":"2723f1f6f5b80dd5","repo":"oxc-project/oxc","slug":"matchers-must-be-called-to-assert","errorCode":null,"errorMessage":"Matchers must be called to assert.","messagePattern":"Matchers must be called to assert\\.","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 in oxlint (via ExpectError::MatcherNotCalled). It fires when a matcher is referenced at the end of an expect chain but never invoked, e.g. `expect(x).toBeDefined` without parentheses. Such a statement performs no assertion at all, so the test passes vacuously.","triggerScenarios":"`parse_expect_jest_fn_call` marks the chain with ExpectError::MatcherNotCalled when the final member of the expect chain (the matcher) is not a CallExpression. Concretely: `expect(value).toBe;`, `expect(fn).toHaveBeenCalled;`, or assigning/passing the matcher as a value instead of calling it.","commonSituations":"Refactors that drop the `()`, copy-paste edits, or code that uses a matcher as a function reference (e.g. `.map(expect)`-style intent). Also seen when converting assertions between libraries and the call shape gets mangled.","solutions":["Add parentheses and any required argument: `expect(true).toBe(true)`, `expect(fn).toHaveBeenCalled()`.","If the matcher genuinely takes no arguments, still call it — `expect(x).toBeDefined()` — never reference it bare.","Delete the dead statement if the assertion was abandoned mid-edit.","If the pattern is intentional in your codebase, disable the rule inline with `// oxlint-disable valid-expect` or turn it off in .oxlintrc.json."],"exampleFix":"// before\nexpect(result).toBeDefined;\n\n// after\nexpect(result).toBeDefined();","handlingStrategy":"validation","validationCode":"// cheap pre-commit scan for referenced-but-uncalled matchers\n// rg \"expect\\([^)]*\\)\\.[a-zA-Z]+\\s*[;,)\" src/ --type ts\nconst fs = require('fs');\nfor (const f of process.argv.slice(2)) {\n  const src = fs.readFileSync(f, 'utf8');\n  if (/expect\\([^)]*\\)\\.[a-zA-Z]\\w*\\s*[;,)]/.test(src)) {\n    console.error(`${f}: matcher referenced without being called`);\n    process.exitCode = 1;\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep jest/vitest `valid-expect` (or oxlint's jest plugin) enabled in CI so a dropped `()` fails the build.","Treat any statement starting with `expect(` that ends in `;` right after an identifier as a review red flag.","Run `oxlint` (or eslint) on save in the editor to catch this at authoring time."],"tags":["jest","vitest","oxlint","testing","assertion","valid-expect"],"backgroundTag":"jest-expect-matcher-not-called","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"}