Struggling to construct a jest test.each
with a tagged template literal
test.each`
height | text
${10} | ${undefined}
${20} | ${undefined}
${10} | ${'text'}
${20} | ${'text'}
`('$height and $text behave as expected', ({ height, text }) => {
//...
});
height
should be a numbertext
should be either a string or undefined
One option would be to specify types in the test function parameters:
({ height, text }: { height: number, text: string? }) => {
//...
});
However, that's not my ideal solution. The generic type accepted by test.each
.
test.each<MyType>`
height | text
// ...
`('$height and $text behave as expected', ({ height, text }) => {
//...
});
Now the challenge is to utilize this type inference for the function parameter types.