Skip to content

vitest/prefer-each Style

What it does

This rule enforces using each rather than manual loops.

Why is this bad?

Manual loops for tests can be less readable and more error-prone. Using each provides a clearer and more concise way to run parameterized tests, improving readability and maintainability.

Examples

Examples of incorrect code for this rule:

js
for (const item of items) {
  describe(item, () => {
    expect(item).toBe("foo");
  });
}

Examples of correct code for this rule:

js
describe.each(items)("item", (item) => {
  expect(item).toBe("foo");
});

References

Released under the MIT License.