ant-design/tests/shared/excludeWarning.tsx
二货爱吃白萝卜 5d3b45551d
test: snapshot of demo warning message (#43947)
* test: init of test

* test: update snapshot

* test: update snapshot

* chore: adjust size limit

* test: update snapshot

* test: update snapshot

* test: update snapshot

* chore: update snapshot

---------

Co-authored-by: lijianan <574980606@qq.com>
2023-08-02 14:20:13 +08:00

37 lines
838 B
TypeScript

// 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);
});
return errorSpy;
}
export default function excludeAllWarning() {
let cleanUp: Function;
beforeAll(() => {
cleanUp = excludeWarning().mockRestore;
});
afterAll(() => {
cleanUp();
});
}