Browse Source

test: Update Message test case sleep -> useFakeTimers (#37983)

pull/37997/head
hms181231 2 years ago
committed by GitHub
parent
commit
3f8962ec3e
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      components/message/__tests__/config.test.ts

5
components/message/__tests__/config.test.ts

@ -1,6 +1,6 @@
import { act } from 'react-dom/test-utils'; import { act } from 'react-dom/test-utils';
import message, { getInstance } from '..'; import message, { getInstance } from '..';
import { sleep } from '../../../tests/utils'; import { waitFakeTimer } from '../../../tests/utils';
import ConfigProvider from '../../config-provider'; import ConfigProvider from '../../config-provider';
describe('message.config', () => { describe('message.config', () => {
@ -87,7 +87,6 @@ describe('message.config', () => {
}); });
it('should be able to config duration', async () => { it('should be able to config duration', async () => {
jest.useRealTimers();
message.config({ message.config({
duration: 0.5, duration: 0.5,
}); });
@ -97,7 +96,7 @@ describe('message.config', () => {
}); });
expect(getInstance()?.component.state.notices).toHaveLength(1); expect(getInstance()?.component.state.notices).toHaveLength(1);
await sleep(1000); await waitFakeTimer();
expect(getInstance()?.component.state.notices).toHaveLength(0); expect(getInstance()?.component.state.notices).toHaveLength(0);
message.config({ message.config({
duration: 3, duration: 3,

Loading…
Cancel
Save