How do I expect an error in an event handler?
it("throws an error if [some cool condition]", () => {
getCoolCheck().mockRejectedValue("You're not cool enough bro...");
const screen = render(<CoolComponent />);
const btn = screen.getByLabelText("Are you cool enough?");
fireEvent.click(btn);
// this throws an intended error... how do I check it?
});
function CoolComponent() {
<button onClick={handleCoolCheck}>Are you cool enough?</button>
async function handleCoolCheck() {
try {
await getCoolCheck();
alert("So cool!")
} catch (e) {
alert(`error occurred while cool checking: ${e}`);
throw e;
}
}
}
Additionally this is not a normal error, but a rejected promise.