jest/consistent-test-it
Enforce one of test or it for defining tests
fixable
test and it are two names for the same function. When a project mixes them at random, readers wonder whether the difference means something. It doesn't.
By default, a test at the top level of a file uses test, and a test inside a describe uses it.
--fix renames the call. It doesn't change the import, so you need to import the new name yourself.
Configure#
Off by default. To turn it on:
bunfig.toml
[lint.rules]
"jest/consistent-test-it" = "error" # or "warn"Every option, set to its default:
bunfig.toml
[lint.rules]
"jest/consistent-test-it" = ["error", {
fn = "test",
withinDescribe = "it",
}]Examples#
example.ts2 problems
import { describe, expect, it, test } from "@jest/globals";
itEnforce test and it usage conventions("adds", () => {
expect(1 + 1).toBe(2);
});
describe("subtract", () => {
testEnforce test and it usage conventions("goes below zero", () => {
expect(1 - 2).toBe(-1);
});
});example.tsNo problems
import { describe, expect, it, test } from "@jest/globals";
test("adds", () => {
expect(1 + 1).toBe(2);
});
describe("subtract", () => {
it("goes below zero", () => {
expect(1 - 2).toBe(-1);
});
});Forms such as it.skip, it.only and it.each are checked too:
example.ts1 problem
import { expect, it } from "@jest/globals";
itEnforce test and it usage conventions.skip("adds", () => {
expect(1 + 1).toBe(2);
});Options#
| Option | Default | What it does |
|---|---|---|
fn | "test" | The name for tests at the top level of a file: "test" or "it". |
withinDescribe | the value of fn if you set it, otherwise "it" | The name for tests inside a describe. |
To use test everywhere, set only fn:
bunfig.toml
[lint.rules]
"jest/consistent-test-it" = ["error", { fn = "test" }]Then it inside a describe is reported too:
example.tswith
{ "fn": "test" }1 problemimport { describe, expect, it } from "@jest/globals";
describe("subtract", () => {
itEnforce test and it usage conventions("goes below zero", () => {
expect(1 - 2).toBe(-1);
});
});