[READ-ONLY] Mirror of https://github.com/vitest-dev/vitest. Next generation testing framework powered by Vite. vitest.dev
test testing-tools vite
12

Configure Feed

Select the types of activity you want to include in your feed.

docs(migration): prefer for naming and use realistic inference break example

Agent-Logs-Url: https://github.com/vitest-dev/vitest/sessions/6d998e4f-2d3e-4c96-a9f4-854f2cc4383e

Co-authored-by: sheremet-va <16173870+sheremet-va@users.noreply.github.com>

authored by

copilot-swe-agent[bot]
sheremet-va
and committed by
GitHub
(May 7, 2026, 3:43 PM UTC) b052cebb df136594

+20 -7
+20 -7
docs/guide/migration.md
··· 34 34 test('example', { concurrent: false }, async () => { /* ... */ }) // [!code ++] 35 35 ``` 36 36 37 - ### Narrower Inference for `test.each` and `describe.each` 37 + ### Narrower Inference for `test.for` and `describe.for` 38 38 39 - `test.each` and `describe.each` now preserve literal types by default for array cases. 39 + `test.for` and `describe.for` now preserve literal types by default for array cases. 40 40 This means callback parameters can be inferred as literal unions (for example `1 | 2`) instead of widened types (for example `number`) without needing `as const`. 41 41 42 - If your callback annotations intentionally reject literal values and relied on wider inference, update those annotations to accept the inferred literal unions. 42 + `test.each` and `describe.each` are compatibility aliases and follow the same typing behavior. 43 + 44 + If your tests rely on wide callback inference, either widen the value before passing it to broader helpers or specify the case type explicitly. 43 45 44 46 ```ts 45 - // Vitest 5 infers `value` as `1 | 2`, so this callback is now too narrow: 46 - test.each([1, 2])('value %s', (value: Exclude<number, 1 | 2>) => {}) // [!code --] 47 + function runWithRuntimeRetry(fn: (retry: number) => void) { 48 + fn(Math.trunc(Math.random() * 10)) 49 + } 47 50 48 - // If you need the previous wide inference, specify the case type explicitly: 49 - test.each<number>([1, 2])('value %s', (value: Exclude<number, 1 | 2>) => {}) // [!code ++] 51 + test.for([1, 2])('retry %s', (retry) => { // [!code --] 52 + runWithRuntimeRetry((runtimeRetry) => { 53 + const sameType: typeof retry = runtimeRetry 54 + // ^ Type 'number' is not assignable to type '1 | 2' 55 + }) 56 + }) 57 + 58 + test.for<number>([1, 2])('retry %s', (retry) => { // [!code ++] 59 + runWithRuntimeRetry((runtimeRetry) => { 60 + const sameType: typeof retry = runtimeRetry 61 + }) 62 + }) 50 63 ``` 51 64 52 65 ### Locators in Commands are Serialized as Objects