Testing · Middle · Question 22 of 75
How do you search inside one part of the page, e.g. one table row?
const row = screen.getByRole("row", { name: /Ann/ });
within(row).getByRole("button", { name: "Delete" });- ✓Correct answer: With
within(element), which scopes queries to that element - 2With
screen.getAllByRole("button")[3] - 3With
row.querySelector("button")
Explanation
Index-based queries break when the order changes; within keeps the test meaningful.