-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Closed as not planned
Labels
Description
Enhance test.each message format:
- positional placeholders such as
%2$s - index of test set to clarify which test set (table row) was used in a failed test
Motivation
- Easier way to customize test messages
- Easier way to find which test set (table row) failed
Example
There are a few ways I can think of
A/ smarter message format like in sprintf-js package
// not a real world example
test.each([[1, 1, 2], [1, 2, 3], [2, 1, 3]])(
'`%3$i` created using .add(%1$i, %2$i)',
(a, b, expected) => {
expect(a + b).toBe(expected);
},
)
Still not sure how to specify optional test set (table row) index
B/ message as a function - more customizable, and in my opinion easier to implement
test.each([[1, 1, 2], [1, 2, 3], [2, 1, 3]])(
(a, b, expected, index) => // or in a similar way
`${index}: ${expectedResult} created using .add(${a}, ${b}) `,
(a, b, expected) => {
expect(a + b).toBe(expected);
},
)
Is this something that could be considered as a helpful feature and implemented in jest?
petrinecp, OndraM-Kentico, tuan231195, r4j4h, rhogeranacleto and 36 moreAlexLomm, hoqpe, alvaro1553 and AlaaMouch