test: Update swicth test case (#38284)

This commit is contained in:
hms181231 2022-10-31 10:22:38 +08:00 committed by GitHub
parent a927ef62a3
commit 9352d24bc4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 5 deletions

View File

@ -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(<Switch />);
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`', () => {

View File

@ -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(<Switch />);
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();
});
});