Image following test case:
it(\'valid emails checks\', () => {
[\'abc@y.com\', \'a@b.nz\'/*, ...*/].map(mail => {
expect(isValid(mail)).toBe(true);
Although it's not a general solution, for the common case of wanting a custom exception message to distinguish items in a loop, you can instead use Jest's test.each.
For example, your sample code:
it('valid emails checks', () => {
['abc@y.com', 'a@b.nz'/*, ...*/].map(mail => {
expect(isValid(mail)).toBe(true);
});
});
Could instead become
test.each(
['abc@y.com', 'a@b.nz'/*, ...*/],
'checks that email %s is valid',
mail => {
expect(isValid(mail)).toBe(true);
}
);
You can use try-catch:
try {
expect(methodThatReturnsBoolean(inputValue)).toBeTruthy();
}
catch (e) {
throw new Error(`Something went wrong with value ${JSON.stringify(inputValue)}`, e);
}