2023-05-05 20:52:44 +08:00
|
|
|
import React from 'react';
|
2023-03-10 14:12:49 +08:00
|
|
|
import Modal from '..';
|
|
|
|
import { render, waitFakeTimer } from '../../../tests/utils';
|
|
|
|
import ConfigProvider from '../../config-provider';
|
|
|
|
import { resetWarned } from '../../_util/warning';
|
|
|
|
|
|
|
|
describe('Modal.confirm warning', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
jest.useFakeTimers();
|
|
|
|
resetWarned();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(async () => {
|
|
|
|
Modal.destroyAll();
|
|
|
|
|
|
|
|
await waitFakeTimer();
|
|
|
|
document.body.innerHTML = '';
|
|
|
|
jest.clearAllTimers();
|
|
|
|
});
|
|
|
|
|
|
|
|
// Follow test need keep order
|
|
|
|
it('no warning', async () => {
|
|
|
|
const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
|
|
|
Modal.confirm({
|
|
|
|
content: <div className="bamboo" />,
|
|
|
|
});
|
|
|
|
await waitFakeTimer();
|
|
|
|
|
|
|
|
expect(document.querySelector('.bamboo')).toBeTruthy();
|
|
|
|
|
|
|
|
expect(errSpy).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('warning if use theme', async () => {
|
|
|
|
const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
|
|
|
render(<ConfigProvider theme={{}} />);
|
|
|
|
|
|
|
|
Modal.confirm({
|
|
|
|
content: <div className="light" />,
|
|
|
|
});
|
|
|
|
await waitFakeTimer();
|
|
|
|
|
|
|
|
expect(document.querySelector('.light')).toBeTruthy();
|
|
|
|
|
|
|
|
expect(errSpy).toHaveBeenCalledWith(
|
|
|
|
"Warning: [antd: Modal] Static function can not consume context like dynamic theme. Please use 'App' component instead.",
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|