Testing · Middle · Question 2 of 75

What is wrong with this waitFor?

await waitFor(async () => {
  await user.click(screen.getByRole("button", { name: "Save" }));
  expect(screen.getByText("Saved")).toBeInTheDocument();
});

Explanation

The callback may run many times, so it should contain only assertions, ideally a single one.

Further reading

Problem with a question

Testing · Middle · question 2

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