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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
7 additions and
12 deletions
-
components/notification/__tests__/config.test.ts
-
components/notification/__tests__/index.test.tsx
|
|
@ -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(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
@ -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); |
|
|
|