Add utility to jest setupTests to detect React hydration errors

This commit is contained in:
Michael Telatynski 2026-03-27 12:05:56 +00:00
parent 24acce9a6c
commit 23dd621fa9
No known key found for this signature in database
GPG Key ID: A2B008A5F49F5D0D

View File

@ -66,3 +66,21 @@ if (env["GITHUB_ACTIONS"] !== undefined) {
require("./setup/setupManualMocks"); // must be first
require("./setup/setupLanguage");
require("./setup/setupConfig");
// Utility to check for React errors during the tests
let errors: any[] = [];
const originalError = console.error;
beforeEach(() => {
errors = [];
jest.spyOn(console, "error").mockImplementation((...args) => {
if (/validateDOMNesting|Hydration failed|hydration error/i.test(args[0])) {
errors.push(args[0]);
}
originalError.call(console, ...args);
});
});
afterEach(() => {
if (errors.length > 0) {
throw new Error("Test failed due to React hydration errors in the console.");
}
});