{"record":{"id":"2d0a427a78eb8ca2","repo":"oxc-project/oxc","slug":"prefix-assertions-expects-a-single-argument-of","errorCode":null,"errorMessage":"`{prefix}.assertions` expects a single argument of type number.","messagePattern":"`(.+?)\\.assertions` expects a single argument of type number\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/shared/jest_vitest/prefer_expect_assertions.rs","lineNumber":174,"sourceCode":"```\n\"#;\n\nfn expect_shadowed_by_parameter(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\n        \"`expect` is shadowed by a callback parameter and cannot be used for assertions.\",\n    )\n    .with_help(\"Rename the parameter to avoid shadowing the global `expect`.\")\n    .with_label(span)\n}\n\npub fn has_assertions_takes_no_arguments(span: Span, prefix: &str) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"`{prefix}.hasAssertions` expects no arguments.\"))\n        .with_help(format!(\"Remove the arguments from `{prefix}.hasAssertions()`.\"))\n        .with_label(span)\n}\n\nfn assertions_requires_one_argument(span: Span, prefix: &str) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"`{prefix}.assertions` expects a single argument of type number.\"))\n        .with_help(format!(\"Pass a single numeric argument to `{prefix}.assertions()`.\"))\n        .with_label(span)\n}\n\nfn assertions_requires_number_argument(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"This argument should be a number.\")\n        .with_help(\"Replace this argument with a numeric literal.\")\n        .with_label(span)\n}\n\npub fn resolve_expect_local_name(ctx: &LintContext<'_>, sources: &[&str]) -> CompactStr {\n    for entry in &ctx.module_record().import_entries {\n        if entry.is_type {\n            continue;\n        }\n\n        let source = entry.module_request.name();\n        if !sources.contains(&source) {","sourceCodeStart":156,"sourceCodeEnd":192,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/shared/jest_vitest/prefer_expect_assertions.rs#L156-L192","documentation":"From the oxlint `prefer-expect-assertions` rule family: `expect.assertions(n)` declares exactly how many assertions the test must run, and its contract is a single numeric argument. Calling it with zero arguments or with several arguments violates that contract, so the linter reports it with this diagnostic telling you to pass exactly one number.","triggerScenarios":"An `expect.assertions()` (or aliased `<prefix>.assertions()`) member call whose arguments array is empty, or whose length is greater than 1 — e.g. `expect.assertions()` or `expect.assertions(1, 2)`.","commonSituations":"Typo/deletion leaving empty parens; refactoring a call that previously took a variable that was moved; misunderstanding assertions() as variadic (e.g. passing a list of expected counts).","solutions":["Count the assertions the test performs and pass that single number: `expect.assertions(3)`.","If you cannot predict the count (loops, conditional assertions), use `expect.hasAssertions()` instead."],"exampleFix":"// before\nit('validates', () => {\n  expect.assertions();\n  expect(a).toBe(1);\n  expect(b).toBe(2);\n});\n\n// after\nit('validates', () => {\n  expect.assertions(2);\n  expect(a).toBe(1);\n  expect(b).toBe(2);\n});","handlingStrategy":"validation","validationCode":"// .oxlintrc.json\n{ \"rules\": { \"jest/prefer-expect-assertions\": \"error\" } }\n\nnpx oxlint tests/","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep assertions() counts in sync whenever you add or remove an assertion in a test (or drop it).","Prefer hasAssertions when the count varies; assertions(n) only when it is fixed."],"tags":["jest","vitest","oxlint","testing","assertions","api-misuse","static-analysis"],"backgroundTag":"expect-assertions-argument-misuse","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"}