Testing · Senior · Question 74 of 75

How can E2E tests catch hydration mismatches and other runtime errors that don't break the visible UI?

const errors: string[] = [];
page.on("console", (msg) => msg.type() === "error" && errors.push(msg.text()));
page.on("pageerror", (error) => errors.push(error.message));
// ...test steps
expect(errors).toEqual([]);

Explanation

React reports hydration mismatches in the console; without a listener the test passes while the page re-renders on the client.

Further reading

Problem with a question

Testing · Senior · question 74

Test yourself

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

Take this quiz