mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-21 13:18:04 +08:00
863f61d908
Co-authored-by: afc163 <afc163@gmail.com>
36 lines
801 B
TypeScript
36 lines
801 B
TypeScript
const originError = console.error;
|
|
|
|
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));
|
|
}
|
|
|
|
/** This function will remove `useLayoutEffect` server side warning. Since it's useless. */
|
|
export function excludeWarning() {
|
|
const errorSpy = jest.spyOn(console, 'error').mockImplementation((msg, ...rest) => {
|
|
if (isSafeWarning(msg)) {
|
|
return;
|
|
}
|
|
originError(msg, ...rest);
|
|
});
|
|
|
|
return errorSpy;
|
|
}
|
|
|
|
export default function excludeAllWarning() {
|
|
let cleanUp: () => void;
|
|
|
|
beforeAll(() => {
|
|
cleanUp = excludeWarning().mockRestore;
|
|
});
|
|
|
|
afterAll(() => {
|
|
cleanUp();
|
|
});
|
|
}
|