Testing · Middle · Question 30 of 75
How do you check that a checkbox is checked?
- ✓Correct answer:
expect(screen.getByRole("checkbox", { name: "Agree" })).toBeChecked() - 2
expect(checkbox.checked).toBe("true") - 3
expect(checkbox).toHaveAttribute("checked")
Explanation
The checked attribute reflects only the initial state; toBeChecked checks the current state and also works with aria-checked.