vitest/consistent-each-for

March 1, 2026 ยท View on GitHub

๐Ÿ“ Enforce using .each or .for consistently.

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

Rule Details

Vitest provides two ways to run parameterized tests: .each and .for. This rule enforces consistency in the usage of these methods.

Key Differences:

  • .each: Spreads array arguments to individual parameters
  • .for: Keeps arrays intact, provides better TestContext support

This rule allows you to configure which method to prefer for different test function types (test, it, describe, suite).

Examples of incorrect code when configured to prefer .for:

// { test: 'for' }
test.each([[1, 1, 2]])('test', (a, b, expected) => {
  expect(a + b).toBe(expected)
})
// { describe: 'for' }
describe.each([[1], [2]])('suite %s', (n) => {
  test('test', () => {})
})

Examples of correct code when configured to prefer .for:

// { test: 'for' }
test.for([[1, 1, 2]])('test', ([a, b, expected]) => {
  expect(a + b).toBe(expected)
})
// { describe: 'for' }
describe.for([[1], [2]])('suite %s', ([n]) => {
  test('test', () => {})
})

Examples of incorrect code when configured to prefer .each:

// { test: 'each' }
test.for([[1, 1, 2]])('test', ([a, b, expected]) => {
  expect(a + b).toBe(expected)
})

Examples of correct code when configured to prefer .each:

// { test: 'each' }
test.each([[1, 1, 2]])('test', (a, b, expected) => {
  expect(a + b).toBe(expected)
})
// { test: 'each' }
test.skip.each([[1, 2]])('test', (a, b) => {
  expect(a).toBeLessThan(b)
})

Options

NameDescriptionTypeChoices
describePreferred method for describe.Stringeach, for
itPreferred method for it.Stringeach, for
suitePreferred method for suite.Stringeach, for
testPreferred method for test.Stringeach, for

Configuration

Typical configuration to enforce .for for tests and .each for describe blocks:

// eslint.config.js
export default [
  {
    rules: {
      'vitest/consistent-each-for': [
        'warn',
        {
          test: 'for',
          it: 'for',
          describe: 'each',
          suite: 'each',
        },
      ],
    },
  },
]

You can configure each function type independently. If a function type is not configured, the rule won't enforce any preference for it.