vitest/consistent-test-it

March 1, 2026 ยท View on GitHub

๐Ÿ“ Enforce using test or it but not both.

โš ๏ธ This rule warns in the ๐ŸŒ all config.

๐Ÿ”ง This rule is automatically fixable by the --fix CLI option.

Rule Details

Examples of incorrect code for this rule:

test('it works', () => {
  // ...
})

it('it works', () => {
  // ...
})

Examples of correct code for this rule:

test('it works', () => {
  // ...
})
test('it works', () => {
  // ...
})

Options

NameDescriptionTypeChoices
fnPreferred global test function keyword.Stringtest, it
withinDescribePreferred test function keyword inside describe.Stringtest, it
{
  "type": "object",
  "properties": {
    "fn": {
      "enum": ["it", "test"]
    },
    "withinDescribe": {
      "enum": ["it", "test"]
    }
  },
  "additionalProperties": false
}
fn

Decides whether to prefer test or it.

withinDescribe

Decides whether to prefer test or it when used within a describe block.

/*eslint vitest/consistent-test-it: ["error", {"fn": "test"}]*/

test('it works', () => {
  // <-- Valid
  // ...
})

test.only('it works', () => {
  // <-- Valid
  // ...
})

it('it works', () => {
  // <-- Invalid
  // ...
})

it.only('it works', () => {
  // <-- Invalid
  // ...
})

The default configuration is top level test and all tests nested with describe to use it.