Fix setupTests.ts

This commit is contained in:
Michael Telatynski 2026-03-27 13:21:06 +00:00
parent a4998e3fe6
commit 6dc6b44a34
No known key found for this signature in database
GPG Key ID: A2B008A5F49F5D0D

View File

@ -73,19 +73,20 @@ require("./setup/setupConfig");
// 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.
// You provided a `checked` prop to a form field without an `onChange` handler.
let errors: any[] = [];
beforeEach(() => {
errors = [];
const originalError = console.error;
jest.spyOn(console, "error").mockImplementation((...args) => {
if (/validateDOMNesting|Hydration failed|hydration error/i.test(args[0])) {
if (/validateDOMNesting|Hydration failed|hydration error|prop to a form field without an/i.test(args[0])) {
errors.push(args[0]);
}
originalError.call(console, ...args);
});
});
afterEach(() => {
mocked(console.error).mockRestore();
mocked(console.error).mockRestore?.();
if (errors.length > 0) {
throw new Error("Test failed due to React hydration errors in the console.");
}