test: console.error should nullable in Console (#39050)

This commit is contained in:
lijianan 2022-11-28 14:19:25 +08:00 committed by GitHub
parent 94049f1406
commit 4efa3b2896
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 16 additions and 21 deletions

View File

@ -2,7 +2,7 @@ describe('Test warning', () => {
let spy: jest.SpyInstance;
beforeAll(() => {
spy = jest.spyOn(console, 'error');
spy = jest.spyOn(console, 'error').mockImplementation(() => {});
});
afterAll(() => {

View File

@ -76,9 +76,8 @@ describe('Alert', () => {
});
it('should show error as ErrorBoundary when children have error', () => {
jest.spyOn(console, 'error').mockImplementation(() => undefined);
// eslint-disable-next-line no-console
expect(console.error).toHaveBeenCalledTimes(0);
const warnSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
expect(warnSpy).toHaveBeenCalledTimes(0);
// @ts-expect-error
// eslint-disable-next-line react/jsx-no-undef
const ThrowError = () => <NotExisted />;
@ -91,8 +90,7 @@ describe('Alert', () => {
expect(screen.getByRole('alert')).toHaveTextContent(
'ReferenceError: NotExisted is not defined',
);
// eslint-disable-next-line no-console
(console.error as any).mockRestore();
warnSpy.mockRestore();
});
it('could be used with Tooltip', async () => {

View File

@ -49,7 +49,7 @@ describe('AutoComplete', () => {
});
it('AutoComplete throws error when contains invalid dataSource', () => {
const spy = jest.spyOn(console, 'error').mockImplementation(() => undefined);
const spy = jest.spyOn(console, 'error').mockImplementation(() => {});
render(
// @ts-ignore
@ -82,13 +82,10 @@ describe('AutoComplete', () => {
});
it('should not warning when getInputElement is null', () => {
jest.spyOn(console, 'warn').mockImplementation(() => undefined);
const warnSpy = jest.spyOn(console, 'warn').mockImplementation(() => {});
render(<AutoComplete placeholder="input here" allowClear />);
// eslint-disable-next-line no-console
expect(console.warn).not.toHaveBeenCalled();
// @ts-ignore
// eslint-disable-next-line no-console
console.warn.mockRestore();
expect(warnSpy).not.toHaveBeenCalled();
warnSpy.mockRestore();
});
it('should not override custom input className', () => {

View File

@ -8,7 +8,7 @@ const { QuarterPicker } = DatePicker;
describe('QuarterPicker', () => {
it('should support style prop', () => {
resetWarned();
const warnSpy = jest.spyOn(console, 'error');
const warnSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
const { container } = render(<QuarterPicker style={{ width: 400 }} />);
expect(container.firstChild).toMatchSnapshot();

View File

@ -116,7 +116,7 @@ describe('Dropdown', () => {
});
it('should warn if use topCenter or bottomCenter', () => {
const error = jest.spyOn(console, 'error');
const error = jest.spyOn(console, 'error').mockImplementation(() => {});
render(
<div>
<Dropdown menu={{ items }} placement="bottomCenter">

View File

@ -1040,7 +1040,7 @@ describe('Menu', () => {
});
it('should not warning deprecated message when items={undefined}', () => {
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => undefined);
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
render(<Menu items={undefined} />);
expect(errorSpy).not.toHaveBeenCalledWith(
expect.stringContaining('`children` will be removed in next major version'),

View File

@ -41,7 +41,7 @@ describe('Modal.confirm triggers callbacks correctly', () => {
// });
// jest.spyOn(window, 'cancelAnimationFrame').mockImplementation(id => window.clearTimeout(id));
const errorSpy = jest.spyOn(console, 'error');
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
/* eslint-disable no-console */
// Hack error to remove act warning

View File

@ -181,7 +181,7 @@ describe('Space', () => {
// https://github.com/ant-design/ant-design/issues/35305
it('should not throw duplicated key warning', () => {
jest.spyOn(console, 'error').mockImplementation(() => undefined);
const spy = jest.spyOn(console, 'error').mockImplementation(() => {});
render(
<Space>
<div key="1" />
@ -190,11 +190,11 @@ describe('Space', () => {
<div />
</Space>,
);
expect(console.error).not.toHaveBeenCalledWith(
expect(spy).not.toHaveBeenCalledWith(
expect.stringContaining('Encountered two children with the same key'),
expect.anything(),
expect.anything(),
);
(console.error as any).mockRestore();
spy.mockRestore();
});
});

View File

@ -117,7 +117,7 @@ describe('Table.filter', () => {
});
it('renders empty menu correctly', () => {
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => undefined);
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
const { container } = render(
createTable({
columns: [