oxc-project/oxc · warning
Enforce `test` and `it` usage conventions
Error message
Enforce `test` and `it` usage conventions
What it means
Diagnostic from oxlint's shared jest/vitest consistent-test-it rule (port of jest/consistent-test-it). It enforces one keyword for test cases: by default `fn` is `test` at the top level and `withinDescribe` is `it` inside describe blocks. The check is string-based: a reported call's parsed jest name must end with the preferred keyword, otherwise this diagnostic (with a 'Prefer using X instead of Y' help) fires and an autofix rewrites the callee.
Source
Thrown at crates/oxc_linter/src/rules/shared/jest_vitest/consistent_test_it.rs:19
use std::borrow::Cow;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use oxc_ast::{AstKind, ast::Expression};
use oxc_diagnostics::OxcDiagnostic;
use oxc_span::{GetSpan, Span};
use crate::{
context::LintContext,
utils::{
JestFnKind, JestGeneralFnKind, ParsedJestFnCallNew, PossibleJestNode,
collect_possible_jest_call_node, parse_jest_fn_call,
},
};
fn consistent_method(preferred_method: &str, other_method: &str, span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Enforce `test` and `it` usage conventions")
.with_help(format!("Prefer using {preferred_method:?} instead of {other_method:?}"))
.with_label(span)
}
fn consistent_method_within_describe(
preferred_method: &str,
other_method: &str,
span: Span,
) -> OxcDiagnostic {
OxcDiagnostic::warn("Enforce `test` and `it` usage conventions")
.with_help(format!(
"Prefer using {preferred_method:?} instead of {other_method:?} within describe"
))
.with_label(span)
}
#[derive(Debug, Clone, Copy, Eq, PartialEq, Deserialize, JsonSchema, Serialize)]
#[serde(rename_all = "lowercase")]View on GitHub (pinned to e1e7af627c)
Solutions
- Apply the provided autofix (rewrites `it(` → `test(` or `test(` → `it(` per scope).
- Standardize the suite with a codemod or search-replace, then let the rule keep it consistent.
- If your team prefers the other keyword, configure it: `"jest/consistent-test-it": ["error", { "fn": "it", "withinDescribe": "it" }]`.
- Disable the rule if mixed usage is acceptable in your repo.
Example fix
// before (defaults: fn=test, withinDescribe=it)
it('works at top level');
describe('unit', () => {
test('works inside describe');
});
// after
test('works at top level');
describe('unit', () => {
it('works inside describe');
}); Defensive patterns
Strategy: validation
Validate before calling
oxlint --jest-plugin test/ # consistent-test-it with optional config:
# { "fn": "it", "withinDescribe": "it" } Prevention
- Pick one keyword convention, encode it in the rule config once, and let the autofix enforce it.
- Remember the oxlint defaults: `test` at top level, `it` inside describe.
- Setting `fn` alone makes withinDescribe inherit it — configure both only if you want the split style.
When it happens
Trigger: `parse_jest_fn_call` resolves the call as a General jest test call, then: top-level `it('x')` / `it.only('x')` with default fn=test reports 'Prefer using "test" instead of "it"'; `test('x')` inside `describe(...)` with default withinDescribe=it reports the within-describe variant. Config `{ "fn": "it" }` flips it, and if withinDescribe is omitted it inherits fn. The fixer also maps `fit` → `test.only` and x-/f-prefixed names accordingly.
Common situations: Mixed-style suites after merging teams or copy-pasting examples; enforcing `it` inside describe (BDD style) while keeping `test` at the top; CI lint failures after enabling the jest plugin category where the rule is on by default.
Related errors
- Use `{preferred_node_name}` instead.
- Suggest using the built-in comparison matchers
- Prefer mock resolved/rejected shorthands for promises.
- Require a message for {matcher_name:?}.
- Prefer `toHaveBeenCalled()` over `toHaveBeenCalledTimes(0)`
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/ed81c95bbb240018.
Report an issue: GitHub.