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([]);- ✓Correct answer: Listen to
consoleandpageerrorevents and fail the test on errors (e.g. in an automatic fixture) - 2Hydration errors are always visible on the screen
- 3Only by reading server logs manually
Explanation
React reports hydration mismatches in the console; without a listener the test passes while the page re-renders on the client.