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" });

Explanation

Index-based queries break when the order changes; within keeps the test meaningful.

Further reading

Problem with a question

Testing · Middle · question 22

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