{"record":{"id":"87de9d4b46a764d3","repo":"oxc-project/oxc","slug":"expect-requires-at-least-argument","errorCode":null,"errorMessage":"Expect requires at least {} argument{} ","messagePattern":"Expect requires at least (.+?) argument(.+?) ","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: `expect()` was called with fewer arguments than `minArgs` requires (default 1). `expect()` with no value cannot assert anything and usually means an incomplete edit or a spread/refactor gone wrong.","triggerScenarios":"`(call_expr.arguments.len() as u32) < self.min_args` emits the formatted 'Expect requires at least N argument(s)' message. Concretely: `expect();`, `expect(...empty)`-style dynamic spreads, or `minArgs` raised in config while existing calls pass nothing.","commonSituations":"Half-written tests after a merge conflict or snippet paste; renaming a variable and accidentally deleting the argument; asserting on nothing while meaning `expect.hasAssertions()`.","solutions":["Pass the value under test: `expect(value)`.","If you meant to assert calls happened, use `expect.hasAssertions()`/`expect.assertions(n)` on a separate line, not `expect()`.","If a wrapper legitimately takes zero args, lower `minArgs` to 0 in the rule config."],"exampleFix":"// before\nexpect();\n\n// after\nexpect(getUser().name);","handlingStrategy":"validation","validationCode":"const empty = /\\bexpect\\s*\\(\\s*\\)/;\nif (empty.test(src)) { console.error('expect() called with no argument'); process.exitCode = 1; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Type the value under test before writing the assertion so an empty expect never compiles conceptually.","Use `expect.hasAssertions()` on its own line when you only want to require assertions happened.","Beware spreads into expect() — they can collapse to zero arguments at runtime."],"tags":["jest","vitest","oxlint","testing","arguments","valid-expect"],"backgroundTag":"expect-argument-count","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"}