oxc-project/oxc · warning
This argument should be a number.
Error message
This argument should be a number.
What it means
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.
Source
Thrown at crates/oxc_linter/src/rules/shared/jest_vitest/prefer_expect_assertions.rs:180
)
.with_help("Rename the parameter to avoid shadowing the global `expect`.")
.with_label(span)
}
pub fn has_assertions_takes_no_arguments(span: Span, prefix: &str) -> OxcDiagnostic {
OxcDiagnostic::warn(format!("`{prefix}.hasAssertions` expects no arguments."))
.with_help(format!("Remove the arguments from `{prefix}.hasAssertions()`."))
.with_label(span)
}
fn assertions_requires_one_argument(span: Span, prefix: &str) -> OxcDiagnostic {
OxcDiagnostic::warn(format!("`{prefix}.assertions` expects a single argument of type number."))
.with_help(format!("Pass a single numeric argument to `{prefix}.assertions()`."))
.with_label(span)
}
fn assertions_requires_number_argument(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("This argument should be a number.")
.with_help("Replace this argument with a numeric literal.")
.with_label(span)
}
pub fn resolve_expect_local_name(ctx: &LintContext<'_>, sources: &[&str]) -> CompactStr {
for entry in &ctx.module_record().import_entries {
if entry.is_type {
continue;
}
let source = entry.module_request.name();
if !sources.contains(&source) {
continue;
}
let crate::module_record::ImportImportName::Name(import_name) = &entry.import_name else {
continue;
};View on GitHub (pinned to e1e7af627c)
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).
Example fix
// before
it('runs each case', () => {
expect.assertions(cases.length);
for (const c of cases) expect(run(c)).toBe(true);
});
// after
it.each(cases)('runs %j', (c) => {
expect(run(c)).toBe(true);
}); Defensive patterns
Strategy: validation
Validate before calling
// .oxlintrc.json
{ "rules": { "jest/prefer-expect-assertions": "error" } }
npx oxlint tests/ Prevention
- 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.
When it happens
Trigger: `expect.assertions('2')`, `expect.assertions(count)` (identifier), `expect.assertions(n * 2)` — an assertions() call with one argument whose expression is not a numeric literal.
Common situations: Dynamic test generation where the count is computed; passing a string digit from config; variables pulled from a fixtures table.
Related errors
- `{prefix}.hasAssertions` expects no arguments.
- `{prefix}.assertions` expects a single argument of type numb
- `expect` must be inside of a test block.
- Suggest using `toBeCalledWith()` or `toHaveBeenCalledWith()`
- Suggest using the built-in equality matchers.
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/5b5cb0c07bac9597.
Report an issue: GitHub.