mirror of
https://gitee.com/element-plus/element-plus.git
synced 2024-12-14 09:20:51 +08:00
67 lines
1.5 KiB
TypeScript
67 lines
1.5 KiB
TypeScript
import { mount } from '@vue/test-utils'
|
|
import { describe, expect, it, vi } from 'vitest'
|
|
import sleep from '@element-plus/test-utils/sleep'
|
|
import RepeatClick from '../repeat-click'
|
|
|
|
let handler: ReturnType<typeof vi.fn>
|
|
|
|
const _mount = () =>
|
|
mount(
|
|
{
|
|
setup() {
|
|
handler = vi.fn()
|
|
return () => (
|
|
<div id="block" v-repeat-click={handler}>
|
|
TEST
|
|
</div>
|
|
)
|
|
},
|
|
},
|
|
{
|
|
global: {
|
|
directives: {
|
|
RepeatClick,
|
|
},
|
|
},
|
|
}
|
|
)
|
|
|
|
describe('Directives.vue', () => {
|
|
it('click test', async () => {
|
|
const wrapper = _mount()
|
|
const block = wrapper.find('#block')
|
|
|
|
block.trigger('mousedown')
|
|
await sleep(330)
|
|
document.dispatchEvent(new MouseEvent('mouseup'))
|
|
|
|
expect(handler).toHaveBeenCalledTimes(3)
|
|
})
|
|
|
|
it('time interval between mousedown and mouseup is slightly less than 100ms', async () => {
|
|
const wrapper = _mount()
|
|
const block = wrapper.find('#block')
|
|
|
|
for (let i = 0; i < 10; i++) {
|
|
block.trigger('mousedown')
|
|
await sleep(99)
|
|
document.dispatchEvent(new MouseEvent('mouseup'))
|
|
}
|
|
|
|
expect(handler).toHaveBeenCalledTimes(10)
|
|
})
|
|
|
|
it('time interval between mousedown and mouseup is slightly more than 100ms', async () => {
|
|
const wrapper = _mount()
|
|
const block = wrapper.find('#block')
|
|
|
|
for (let i = 0; i < 10; i++) {
|
|
block.trigger('mousedown')
|
|
await sleep(101)
|
|
document.dispatchEvent(new MouseEvent('mouseup'))
|
|
}
|
|
|
|
expect(handler).toHaveBeenCalledTimes(10)
|
|
})
|
|
})
|