Testing · Junior · Question 55 of 78

How do you check the result of clicking a counter button?

const user = userEvent.setup();
render(<Counter />);
await user.click(screen.getByRole("button", { name: "+" }));

Explanation

Check what the user sees, not the component's internal state.

Further reading

Problem with a question

Testing · Junior · question 55

Test yourself

Take the Testing · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz