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

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

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

Loading…
Cancel
Save