diff --git a/components/switch/__tests__/index.test.tsx b/components/switch/__tests__/index.test.tsx
index f5b9835864..21870ef3cf 100644
--- a/components/switch/__tests__/index.test.tsx
+++ b/components/switch/__tests__/index.test.tsx
@@ -3,7 +3,7 @@ import Switch from '..';
import focusTest from '../../../tests/shared/focusTest';
import mountTest from '../../../tests/shared/mountTest';
import rtlTest from '../../../tests/shared/rtlTest';
-import { sleep, fireEvent, render } from '../../../tests/utils';
+import { waitFakeTimer, fireEvent, render } from '../../../tests/utils';
import { resetWarned } from '../../_util/warning';
describe('Switch', () => {
@@ -12,10 +12,13 @@ describe('Switch', () => {
rtlTest(Switch);
it('should has click wave effect', async () => {
+ jest.useFakeTimers();
const { container } = render();
fireEvent.click(container.querySelector('.ant-switch')!);
- await sleep(0);
+ await waitFakeTimer();
expect(container.querySelector('button')!.getAttribute('ant-click-animating')).toBe('true');
+ jest.clearAllTimers();
+ jest.useRealTimers();
});
it('warning if set `value`', () => {
diff --git a/components/switch/__tests__/wave.test.tsx b/components/switch/__tests__/wave.test.tsx
index 6d18ac3f74..deb8333927 100644
--- a/components/switch/__tests__/wave.test.tsx
+++ b/components/switch/__tests__/wave.test.tsx
@@ -1,17 +1,18 @@
import React from 'react';
import Switch from '..';
-import { sleep, render, fireEvent } from '../../../tests/utils';
+import { waitFakeTimer, render, fireEvent } from '../../../tests/utils';
describe('click wave effect', () => {
async function click(container: HTMLElement) {
fireEvent.click(container.querySelector('.ant-switch')!);
container.querySelector('.ant-switch')!.dispatchEvent(new Event('transitionstart'));
- await sleep(20);
+ await waitFakeTimer();
container.querySelector('.ant-switch')!.dispatchEvent(new Event('animationend'));
- await sleep(20);
+ await waitFakeTimer();
}
it('should have click wave effect', async () => {
+ jest.useFakeTimers();
const { container } = render();
await click(container);
await click(container);
@@ -23,5 +24,7 @@ describe('click wave effect', () => {
const event = new Event('animationend');
Object.assign(event, { animationName: 'fadeEffect' });
container.querySelector('.ant-switch')!.dispatchEvent(event);
+ jest.clearAllTimers();
+ jest.useRealTimers();
});
});