Browse Source

test: Update Notification test case sleep -> useFakeTimers (#37985)

* test: Update Notification test case sleep -> useFakeTimers

* test: Update Notification test case sleep -> useFakeTimers
pull/37997/head
hms181231 2 years ago
committed by GitHub
parent
commit
56fe1ceeaa
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      components/notification/__tests__/config.test.ts
  2. 4
      components/notification/__tests__/index.test.tsx

15
components/notification/__tests__/config.test.ts

@ -1,5 +1,5 @@
import notification, { getInstance } from '..';
import { sleep, act } from '../../../tests/utils';
import { waitFakeTimer, act } from '../../../tests/utils';
describe('notification.config', () => {
beforeEach(() => {
@ -32,24 +32,19 @@ describe('notification.config', () => {
});
});
await act(async () => {
await Promise.resolve();
});
await waitFakeTimer();
expect(document.querySelectorAll('.ant-notification-notice').length).toBe(5);
expect(document.querySelectorAll('.ant-notification-notice')[4]?.textContent).toBe(
'Notification last',
);
act(() => {
jest.runAllTimers();
});
await waitFakeTimer();
await act(async () => {
await sleep(500);
});
expect((await getInstance('ant-notification-topRight'))?.component.state.notices).toHaveLength(
0,
);
jest.useRealTimers();
});
});

4
components/notification/__tests__/index.test.tsx

@ -1,7 +1,7 @@
import React from 'react';
import { UserOutlined } from '@ant-design/icons';
import notification, { getInstance, type NotificationInstance } from '..';
import { sleep, act } from '../../../tests/utils';
import { waitFakeTimer, act } from '../../../tests/utils';
import ConfigProvider from '../../config-provider';
Object.defineProperty(globalThis, 'IS_REACT_ACT_ENVIRONMENT', {
@ -39,7 +39,7 @@ describe('notification', () => {
});
}
await sleep();
await waitFakeTimer();
const count = document.querySelectorAll('.additional-holder').length;
expect(count).toEqual(1);

Loading…
Cancel
Save