Given this sample test using TypeScript and Jest based on https://jestjs.io/docs/api#testeachtablename-fn-timeout
it.each([
{ numbers: [1, 2, 3] },
{ numbers: [4, 5, 6] }
])('Test case %#: Amount is $numbers.length => $numbers', ({ numbers }) => {
expect(true).toBeTruthy();
});
The test runner only prints
✓ Test case 0: Amount is $numbers.length => $numbers (4ms)
Is there a way I can replace $numbers with its value and work with it? E.g. calling array functions on it.
A working alternative would be
[
[1, 2, 3],
[4, 5, 6]
].forEach((numbers, index) => {
it(`Test case ${index}: Amount is ${numbers.length} => ${numbers}`, () => {
expect(true).toBeTruthy();
})
});
but I don't know if this is the suggested way.
You can accomplish this with the template literal implementation of test.each, e.g.:
test.each`
input | expectation
${1} | ${'expected-1'}
${2} | ${'expected-2'}
${3} | ${'expected-3'}
`('When the input=$input should return $expectation', ({ input, expectation }) => { ...
Note a couple of things about this:
${ }.| to delimit the columns{ input, expectation} instead of input, expectation)