Testing · Junior · Question 52 of 78
How do you find an input by its label?
<label htmlFor="email">Email</label>
<input id="email" />- ✓Correct answer:
screen.getByLabelText("Email") - 2
screen.getByText("Email") - 3
screen.getByRole("label")
Explanation
The query fails if the label isn't connected to the input - a useful accessibility check. getByRole("textbox", { name: "Email" }) works too.