{"record":{"id":"5b5cb0c07bac9597","repo":"oxc-project/oxc","slug":"this-argument-should-be-a-number","errorCode":null,"errorMessage":"This argument should be a number.","messagePattern":"This argument should be a number\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/shared/jest_vitest/prefer_expect_assertions.rs","lineNumber":180,"sourceCode":"    )\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) {\n            continue;\n        }\n\n        let crate::module_record::ImportImportName::Name(import_name) = &entry.import_name else {\n            continue;\n        };","sourceCodeStart":162,"sourceCodeEnd":198,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/shared/jest_vitest/prefer_expect_assertions.rs#L162-L198","documentation":"From the oxlint `prefer-expect-assertions` rule family: even when `expect.assertions()` receives exactly one argument, that argument must be a numeric literal (Jest compares the executed-assertion count to it). This companion diagnostic fires on the argument itself when it is not a number — strings, identifiers, or expressions make the declared count unverifiable or wrong at runtime.","triggerScenarios":"`expect.assertions('2')`, `expect.assertions(count)` (identifier), `expect.assertions(n * 2)` — an assertions() call with one argument whose expression is not a numeric literal.","commonSituations":"Dynamic test generation where the count is computed; passing a string digit from config; variables pulled from a fixtures table.","solutions":["Replace the argument with a plain numeric literal after counting the assertions.","If the count is genuinely dynamic, drop `expect.assertions` and use `expect.hasAssertions()`.","Restructure the test so the number of assertions is static (e.g. unroll a loop of assertions)."],"exampleFix":"// before\nit('runs each case', () => {\n  expect.assertions(cases.length);\n  for (const c of cases) expect(run(c)).toBe(true);\n});\n\n// after\nit.each(cases)('runs %j', (c) => {\n  expect(run(c)).toBe(true);\n});","handlingStrategy":"validation","validationCode":"// .oxlintrc.json\n{ \"rules\": { \"jest/prefer-expect-assertions\": \"error\" } }\n\nnpx oxlint tests/","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only literal numbers are valid; hoist dynamic counts out by restructuring the test (it.each).","Treat a non-literal argument as a design smell that the test's assertion count is not static."],"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"}