Skip to content

Latest commit

 

History

History
124 lines (92 loc) · 2.42 KB

consistent-test-it.md

File metadata and controls

124 lines (92 loc) · 2.42 KB

vitest/consistent-test-it

📝 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

By default, this rule enforces test at the top level, and it inside a describe block.

Examples of incorrect code for this rule:

test('using test function', () => {
  // ...
})

// Invalid: the top level keyword defaults to `test`
it('using it function', () => {
  // ...
})

Examples of correct code for this rule:

test('using test function', () => {
  // ...
})

test('using only test function', () => {
  // ...
})

Options

Name Description Type Choices
fn Preferred global test function keyword. String test, it
withinDescribe Preferred test function keyword inside describe. String test, it
{
  "type": "object",
  "properties": {
    "fn": {
      "enum": ["it", "test"]
    },
    "withinDescribe": {
      "enum": ["it", "test"]
    }
  },
  "additionalProperties": false
}
fn

Decides whether to prefer test or it. Defaults to test.

/*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
  // ...
})
withinDescribe

Decides whether to prefer test or it when used within a describe block. Defaults to the value of fn when it is set, otherwise it.

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

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

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

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

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

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