-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Closed
Description
🐛 Bug Report
The doc says the argument of toThrow() can be a class for the error, it works when a promise throws an Error instance, but fails when the promise throws a custom object.
To Reproduce
describe('When a promise throws an expression, rejects.toThrow should match the expression by its type', () => {
it('when the expression is an error', async () => {
const p = new Promise(() => {
throw new Error('some-info');
});
await expect(p).rejects.toThrow(Error); // passed
});
it('when the expression is a custom object', async () => {
class Exception {
constructor(public readonly message: string) {
}
}
const p = new Promise(() => {
throw new Exception('some-info');
});
await expect(p).rejects.toThrow(Exception); // failed
});
});
The first test passes, while the second test fails with the following message:
Expected the function to throw an error of type:
"Exception"
But it didn't throw anything.
Expected behavior
Both the above two tests pass.