# vitest/consistent-each-for

> Enforce either `.each` or `.for` for parameterized tests

Vitest has two ways to run a test once per row of data. `test.each` spreads an array row into separate arguments. `test.for` passes the row as one argument. When a project mixes them, you have to check which one a test uses before you can read its callback's parameters.

The rule does nothing until you choose a method for at least one function.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

```toml bunfig.toml
[lint.rules]
"vitest/consistent-each-for" = "error" # or "warn"
```

Every option, set to its default. The ones that are commented out are unset by default.

```toml bunfig.toml
[lint.rules]
"vitest/consistent-each-for" = ["error", {
  # test = <value>,
  # it = <value>,
  # describe = <value>,
  # suite = <value>,
}]
```

{/* End of the generated section. */}

## Examples

```toml bunfig.toml
[lint.rules]
"vitest/consistent-each-for" = ["error", { test = "for" }]
```

Reported:

{/* bad {"options": [{"test": "for"}]} */}
```ts
import { expect, test } from "vitest";

test.each([
  [1, 2, 3],
  [2, 3, 5],
])("adds %i and %i", (a, b, sum) => {
  expect(a + b).toBe(sum);
});
```

Not reported:

{/* good {"options": [{"test": "for"}]} */}
```ts
import { expect, test } from "vitest";

test.for([
  [1, 2, 3],
  [2, 3, 5],
])("adds %i and %i", ([a, b, sum]) => {
  expect(a + b).toBe(sum);
});
```

## Options

Each option takes the method you want, `"each"` or `"for"`. A function you leave out isn't checked.

| Option | Default | What it does |
| --- | --- | --- |
| `test` | not checked | The method for `test`. |
| `it` | not checked | The method for `it`. |
| `describe` | not checked | The method for `describe`. |
| `suite` | not checked | The method for `suite`. |

`test` and `it` are separate settings. If you only set `test`, `it.each` is still allowed:

{/* good {"options": [{"test": "for"}]} */}
```ts
import { expect, it } from "vitest";

it.each([1, 2, 3])("accepts %i", (value) => {
  expect(value).toBeGreaterThan(0);
});
```
