mirror of
https://github.com/ant-design/ant-design.git
synced 2025-07-24 15:38:45 +08:00
test: Update swicth test case (#38284)
This commit is contained in:
parent
a927ef62a3
commit
9352d24bc4
@ -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`', () => {
|
||||
|
@ -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();
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user