2023-05-06 15:49:37 +08:00
|
|
|
import * as React from 'react';
|
2023-03-10 14:12:49 +08:00
|
|
|
import Modal from '..';
|
|
|
|
import { render, waitFakeTimer } from '../../../tests/utils';
|
|
|
|
import { resetWarned } from '../../_util/warning';
|
2023-06-07 11:54:50 +08:00
|
|
|
import ConfigProvider from '../../config-provider';
|
2023-03-10 14:12:49 +08:00
|
|
|
|
|
|
|
describe('Modal.confirm warning', () => {
|
|
|
|
beforeEach(() => {
|
2023-06-07 21:59:21 +08:00
|
|
|
jest.useFakeTimers();
|
2023-03-10 14:12:49 +08:00
|
|
|
resetWarned();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(async () => {
|
|
|
|
Modal.destroyAll();
|
|
|
|
|
|
|
|
await waitFakeTimer();
|
|
|
|
document.body.innerHTML = '';
|
2023-06-07 21:59:21 +08:00
|
|
|
jest.clearAllTimers();
|
2023-03-10 14:12:49 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
// Follow test need keep order
|
|
|
|
it('no warning', async () => {
|
2023-06-07 21:59:21 +08:00
|
|
|
const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
2023-03-10 14:12:49 +08:00
|
|
|
Modal.confirm({
|
|
|
|
content: <div className="bamboo" />,
|
|
|
|
});
|
|
|
|
await waitFakeTimer();
|
|
|
|
|
|
|
|
expect(document.querySelector('.bamboo')).toBeTruthy();
|
|
|
|
|
|
|
|
expect(errSpy).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('warning if use theme', async () => {
|
2023-06-07 21:59:21 +08:00
|
|
|
const errSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
2023-03-10 14:12:49 +08:00
|
|
|
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.",
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|