2021-10-12 13:14:26 +08:00
|
|
|
// eslint-disable-next-line no-console
|
2021-08-31 15:51:02 +08:00
|
|
|
const originError = console.error;
|
|
|
|
|
2023-08-02 14:20:13 +08:00
|
|
|
export function isSafeWarning(message: boolean, all = false) {
|
|
|
|
const list = ['useLayoutEffect does nothing on the server'];
|
|
|
|
|
|
|
|
if (all) {
|
|
|
|
list.push('is deprecated in StrictMode');
|
|
|
|
}
|
|
|
|
|
|
|
|
return list.some((msg) => String(message).includes(msg));
|
|
|
|
}
|
|
|
|
|
2021-08-31 15:51:02 +08:00
|
|
|
/** This function will remove `useLayoutEffect` server side warning. Since it's useless. */
|
|
|
|
export function excludeWarning() {
|
2023-06-07 21:59:21 +08:00
|
|
|
const errorSpy = jest.spyOn(console, 'error').mockImplementation((msg, ...rest) => {
|
2023-08-02 14:20:13 +08:00
|
|
|
if (isSafeWarning(msg)) {
|
2021-08-31 15:51:02 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
originError(msg, ...rest);
|
|
|
|
});
|
|
|
|
|
2022-09-14 11:34:49 +08:00
|
|
|
return errorSpy;
|
2021-08-31 15:51:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export default function excludeAllWarning() {
|
2024-06-22 21:59:12 +08:00
|
|
|
let cleanUp: () => void;
|
2021-08-31 15:51:02 +08:00
|
|
|
|
|
|
|
beforeAll(() => {
|
2022-09-14 11:34:49 +08:00
|
|
|
cleanUp = excludeWarning().mockRestore;
|
2021-08-31 15:51:02 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
afterAll(() => {
|
|
|
|
cleanUp();
|
|
|
|
});
|
|
|
|
}
|