Testing · Middle · Question 74 of 75
How do you check that “Submit” is disabled until the form is valid?
const submit = screen.getByRole("button", { name: "Submit" });
expect(submit).toBeDisabled();
await user.type(screen.getByLabelText("Email"), "ann@example.com");
expect(submit).toBeEnabled();- ✓Correct answer: As shown: assert
toBeDisabled, fill the form like a user, then asserttoBeEnabled - 2Check the component's
isValidstate - 3Click the button and expect an exception
Explanation
toBeDisabled also covers buttons disabled by a parent <fieldset disabled>.