Testing · Junior · Question 25 of 78
How do you check that a promise rejects?
- ✓Correct answer:
await expect(fetchUser(-1)).rejects.toThrow("Not found") - 2
expect(fetchUser(-1)).toThrow("Not found") - 3
expect(await fetchUser(-1)).toBeUndefined()
Explanation
.resolves/.rejects unwrap the promise. Don't forget await (or return), otherwise the assertion isn't awaited.