mirror of
https://github.com/vector-im/element-web.git
synced 2026-05-06 04:36:21 +02:00
Iterate jest utility
This commit is contained in:
parent
23dd621fa9
commit
fab481cd8f
@ -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.");
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user