-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Closed
Description
🐛 Bug Report
It seems like last changes in toThrow (#7621) broke a behaviour uses were relying on in Jest 23.
We can expect toThrow to behave like toEqual on the thrown error, but that's not the case anymore.
To Reproduce
Steps to reproduce the behavior:
Run this test with Jest 23 and Jest 24.0.0-alpha.13:
class CustomError { // not extending Error!
constructor(message) {
this.message = message;
}
}
function throwError() {
throw new CustomError('foo');
}
test('toThrow', () => {
expect(throwError).toThrowError(new CustomError('foo'));
});
test('toEqual', () => {
try {
throwError();
} catch (e) {
expect(e).toEqual(new CustomError('foo'));
return;
}
throw new Error('Expected error here');
});Expected behavior
No errors. Those two tests should be equivalent.
Also, I found the error message a bit confusing:
