Skip to content
← Back to rules

vitest/consistent-test-it Style

🛠️ An auto-fix is available for this rule.

What it does ​

Vitest allows you to choose how you want to define your tests, using the it or the test keywords, with multiple permutations for each:

  • it: it, it.only, it.skip, it.concurrent, it.each.
  • test: test, test.only, test.skip, test.concurrent, test.each.

Why is this bad? ​

It's a good practice to be consistent in your test suite, so that all tests are written in the same way.

Configuration ​

This rule accepts a configuration object with the following properties:

fn ​

type: "it" | "test"

default: "test"

Decides whether to use test or it.

Examples of incorrect code for { "fn": "test" }:

javascript
it("foo");
it.only("foo");

Examples of correct code for { "fn": "test" }:

javascript
test("foo");
test.only("foo");

Examples of incorrect code for { "fn": "it" }:

javascript
test("foo");
test.only("foo");

Examples of correct code for { "fn": "it" }:

javascript
it("foo");
it.only("foo");

withinDescribe ​

type: "it" | "test"

default: "it"

Decides whether to use test or it within a describe scope. If only fn is provided, this will default to the value of fn.

Examples of incorrect code for { "withinDescribe": "test" }:

javascript
describe("foo", function () {
  it("bar");
});

Examples of correct code for { "withinDescribe": "test" }:

javascript
describe("foo", function () {
  test("bar");
});

How to use ​

To enable this rule using the config file or in the CLI, you can use:

json
{
  "plugins": ["vitest"],
  "rules": {
    "vitest/consistent-test-it": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  plugins: ["vitest"],
  rules: {
    "vitest/consistent-test-it": "error",
  },
});
bash
oxlint --deny vitest/consistent-test-it --vitest-plugin

Version ​

This rule was added in v0.5.3.

References ​