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();

Explanation

toBeDisabled also covers buttons disabled by a parent <fieldset disabled>.

Further reading

Problem with a question

Testing · Middle · question 74

Test yourself

Take the Testing · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz