mirror of
https://github.com/vector-im/element-web.git
synced 2026-05-08 13:46:16 +02:00
Add utility to jest setupTests to detect React hydration errors
This commit is contained in:
parent
24acce9a6c
commit
23dd621fa9
@ -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.");
|
||||
}
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user