You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,6 +24,7 @@
24
24
-`[jest-runtime]` Support `import.meta.resolve` ([#14930](https://github.com/jestjs/jest/pull/14930))
25
25
-`[@jest/schemas]` Upgrade `@sinclair/typebox` to v0.31 ([#14072](https://github.com/jestjs/jest/pull/14072))
26
26
-`[@jest/types]``test.each()`: Accept a readonly (`as const`) table properly ([#14565](https://github.com/jestjs/jest/pull/14565))
27
+
-`[@jest/types]` Improve argument type inference passed to `test` and `describe` callback functions from `each` tables ([#14920](https://github.com/jestjs/jest/pull/14920))
27
28
-`[jest-snapshot]`[**BREAKING**] Add support for [Error causes](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause) in snapshots ([#13965](https://github.com/facebook/jest/pull/13965))
28
29
-`[jest-snapshot]` Support Prettier 3 ([#14566](https://github.com/facebook/jest/pull/14566))
29
30
-`[pretty-format]`[**BREAKING**] Do not render empty string children (`''`) in React plugin ([#14470](https://github.com/facebook/jest/pull/14470))
`('template literal example same type', ({a, b, expected}) => {
1064
+
// all arguments are of type `number` because all inputs (a, b, expected) are of type `number`
1065
1065
});
1066
1066
```
1067
1067
1068
-
Otherwise it will require a generic type argument:
1068
+
If the inputs have different types, the arguments will be typed as a union of all the input types (i.e. type of the variables inside the template literal):
1069
+
1070
+
```ts
1071
+
import {test} from'@jest/globals';
1072
+
1073
+
test.each`
1074
+
a | b | expected
1075
+
${1} | ${2} | ${'three'}
1076
+
${3} | ${4} | ${'seven'}
1077
+
${5} | ${6} | ${'eleven'}
1078
+
`('template literal example different types', ({a, b, expected}) => {
1079
+
// all arguments are of type `number | string` because some inputs (a, b) are of type `number` and some others (expected) are of type `string`
1080
+
});
1081
+
```
1082
+
1083
+
Otherwise, if you want each argument to have the right type, you have to explicitly provide the generic type argument:
0 commit comments