Parameterized Tests: each & for in Vitest
From the Vitest cheat sheet ยท Test Structure ยท verified Nov 2026
Parameterized Tests: each & for
Run the same test or suite against a table of inputs
typescript
test.each([
[1, 1, 2],
[2, 3, 5],
])('add(%i, %i) -> %i', (a, b, expected) => {
expect(add(a, b)).toBe(expected)
})
test.for([
{ a: 1, b: 1, sum: 2 },
])('add($a, $b) = $sum', ({ a, b, sum }) => {
expect(add(a, b)).toBe(sum)
})๐ก Prefer test.for: it exposes the test context for concurrent tests
๐ test.each spreads array rows into args; test.for passes the row
๐ v5 no longer quotes strings in ${D}name titles: case a1, not 'a1'
โก describe.each repeats a whole suite for every case
eachforparameterizeddata-driven
Continue with Vitest
Save the full cheat sheet or work through every related task.