2023-06-07 11:54:50 +08:00
|
|
|
import message, { actDestroy, actWrapper } from '..';
|
2022-05-11 14:26:18 +08:00
|
|
|
import { act } from '../../../tests/utils';
|
|
|
|
import { awaitPromise, triggerMotionEnd } from './util';
|
|
|
|
|
|
|
|
describe('call close immediately', () => {
|
|
|
|
beforeAll(() => {
|
|
|
|
actWrapper(act);
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
actDestroy();
|
2023-06-07 21:59:21 +08:00
|
|
|
jest.useFakeTimers();
|
2022-05-11 14:26:18 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(async () => {
|
|
|
|
// Clean up
|
|
|
|
message.destroy();
|
|
|
|
await triggerMotionEnd();
|
|
|
|
|
|
|
|
act(() => {
|
2023-06-07 21:59:21 +08:00
|
|
|
jest.runAllTimers();
|
2022-05-11 14:26:18 +08:00
|
|
|
});
|
|
|
|
|
2023-06-07 21:59:21 +08:00
|
|
|
jest.useRealTimers();
|
2022-05-11 14:26:18 +08:00
|
|
|
|
|
|
|
await awaitPromise();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('open', async () => {
|
|
|
|
const closeFn = message.open({
|
|
|
|
content: '',
|
|
|
|
});
|
|
|
|
closeFn();
|
|
|
|
|
|
|
|
await awaitPromise();
|
|
|
|
|
|
|
|
expect(document.querySelectorAll('.ant-message-notice')).toHaveLength(0);
|
|
|
|
|
|
|
|
// Created close
|
|
|
|
const closeFn2 = message.open({
|
|
|
|
content: 'showed',
|
|
|
|
});
|
|
|
|
await awaitPromise();
|
|
|
|
expect(document.querySelectorAll('.ant-message-notice')).toHaveLength(1);
|
|
|
|
|
|
|
|
closeFn2();
|
|
|
|
await triggerMotionEnd();
|
|
|
|
expect(document.querySelectorAll('.ant-message-notice')).toHaveLength(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('info', async () => {
|
|
|
|
const closeFn = message.info('Message1', 0);
|
|
|
|
closeFn();
|
|
|
|
|
|
|
|
await awaitPromise();
|
|
|
|
|
|
|
|
expect(document.querySelectorAll('.ant-message-notice')).toHaveLength(0);
|
|
|
|
});
|
|
|
|
});
|