Image following test case:
it(\'valid emails checks\', () => {
[\'abc@y.com\', \'a@b.nz\'/*, ...*/].map(mail => {
expect(isValid(mail)).toBe(true);
You can rewrite the expect
assertion to use toThrow()
or not.toThrow()
. Then throw an Error with your custom text. jest
will include the custom text in the output.
// Closure which returns function which may throw
function isValid (email) {
return () => {
// replace with a real test!
if (email !== 'some@example.com') {
throw new Error(`Email ${email} not valid`)
}
}
}
expect(isValid(email)).not.toThrow()