Yuki Zhang
2 years ago
committed by
GitHub
8 changed files with 38 additions and 37 deletions
@ -1,27 +0,0 @@ |
|||||
import { mount } from 'enzyme'; |
|
||||
import React from 'react'; |
|
||||
import Switch from '..'; |
|
||||
import { sleep } from '../../../tests/utils'; |
|
||||
|
|
||||
describe('click wave effect', () => { |
|
||||
async function click(wrapper) { |
|
||||
wrapper.find('.ant-switch').getDOMNode().click(); |
|
||||
wrapper.find('.ant-switch').getDOMNode().dispatchEvent(new Event('transitionstart')); |
|
||||
await sleep(20); |
|
||||
wrapper.find('.ant-switch').getDOMNode().dispatchEvent(new Event('animationend')); |
|
||||
await sleep(20); |
|
||||
} |
|
||||
|
|
||||
it('should have click wave effect', async () => { |
|
||||
const wrapper = mount(<Switch />); |
|
||||
await click(wrapper); |
|
||||
const waveInstance = wrapper.find('InternalWave').instance(); |
|
||||
const resetEffect = jest.spyOn(waveInstance, 'resetEffect'); |
|
||||
await click(wrapper); |
|
||||
expect(resetEffect).toHaveBeenCalledTimes(1); |
|
||||
const event = new Event('animationend'); |
|
||||
Object.assign(event, { animationName: 'fadeEffect' }); |
|
||||
wrapper.find('.ant-switch').getDOMNode().dispatchEvent(event); |
|
||||
resetEffect.mockRestore(); |
|
||||
}); |
|
||||
}); |
|
@ -0,0 +1,27 @@ |
|||||
|
import React from 'react'; |
||||
|
import Switch from '..'; |
||||
|
import { sleep, 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); |
||||
|
container.querySelector('.ant-switch')!.dispatchEvent(new Event('animationend')); |
||||
|
await sleep(20); |
||||
|
} |
||||
|
|
||||
|
it('should have click wave effect', async () => { |
||||
|
const { container } = render(<Switch />); |
||||
|
await click(container); |
||||
|
await click(container); |
||||
|
|
||||
|
expect( |
||||
|
container.querySelector('.ant-switch')!.getAttribute('ant-switch-click-animating'), |
||||
|
).toBeFalsy(); |
||||
|
|
||||
|
const event = new Event('animationend'); |
||||
|
Object.assign(event, { animationName: 'fadeEffect' }); |
||||
|
container.querySelector('.ant-switch')!.dispatchEvent(event); |
||||
|
}); |
||||
|
}); |
Loading…
Reference in new issue