Reputation: 2989
I have this test in Jest that throws an Exception and pass the test
await expect(hotelService.getByIdAsync(Identifier)).rejects.toThrow(FunctionalError);
but when I do
const action = async () => {
await hotelService.getByIdAsync(Identifier);
};
expect(action).toThrowError(FunctionalError);
I have this result: Received function did not throw
Upvotes: 1
Views: 152
Reputation: 24565
You forgot to actually call action
, change it to:
it('should throw', async () => {
await expect(action()).rejects.toThrowError(FunctionalError);
});
Upvotes: 2