Iterate jest utility

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

View File

@ -68,10 +68,15 @@ require("./setup/setupLanguage");
require("./setup/setupConfig");
// Utility to check for React errors during the tests
// Fails tests on errors like the following:
// In HTML, <div> cannot be a descendant of <p>.
// In HTML, <form> cannot be a descendant of <form>.
// In HTML, text nodes cannot be a child of <thead>.
// This will cause a hydration error.
let errors: any[] = [];
const originalError = console.error;
beforeEach(() => {
errors = [];
const originalError = console.error;
jest.spyOn(console, "error").mockImplementation((...args) => {
if (/validateDOMNesting|Hydration failed|hydration error/i.test(args[0])) {
errors.push(args[0]);
@ -80,6 +85,7 @@ beforeEach(() => {
});
});
afterEach(() => {
mocked(console.error).mockRestore();
if (errors.length > 0) {
throw new Error("Test failed due to React hydration errors in the console.");
}