ant-design/tests/shared/excludeWarning.ts

37 lines
840 B
TypeScript
Raw Normal View History

// eslint-disable-next-line no-console
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);
});
2022-09-14 11:34:49 +08:00
return errorSpy;
}
export default function excludeAllWarning() {
let cleanUp: () => void;
beforeAll(() => {
2022-09-14 11:34:49 +08:00
cleanUp = excludeWarning().mockRestore;
});
afterAll(() => {
cleanUp();
});
}