2020-09-16 14:49:21 +08:00
|
|
|
import { mount } from '@vue/test-utils'
|
2022-04-20 17:02:44 +08:00
|
|
|
import { describe, expect, test, vi } from 'vitest'
|
2022-04-19 12:46:57 +08:00
|
|
|
import sleep from '@element-plus/test-utils/sleep'
|
2020-09-16 14:49:21 +08:00
|
|
|
import RepeatClick from '../repeat-click'
|
|
|
|
|
2022-04-19 12:46:57 +08:00
|
|
|
const handler = vi.fn()
|
2021-09-04 19:29:28 +08:00
|
|
|
const _mount = () =>
|
2022-07-12 19:42:38 +08:00
|
|
|
mount(
|
|
|
|
{
|
|
|
|
setup() {
|
|
|
|
return () => (
|
|
|
|
<div id="block" v-repeat-click={handler}>
|
|
|
|
TEST
|
|
|
|
</div>
|
|
|
|
)
|
2021-09-04 19:29:28 +08:00
|
|
|
},
|
|
|
|
},
|
2022-07-12 19:42:38 +08:00
|
|
|
{
|
|
|
|
global: {
|
|
|
|
directives: {
|
|
|
|
RepeatClick,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
)
|
2020-09-16 14:49:21 +08:00
|
|
|
|
|
|
|
describe('Directives.vue', () => {
|
|
|
|
test('Click test', async () => {
|
|
|
|
const wrapper = _mount()
|
|
|
|
const block = wrapper.find('#block')
|
|
|
|
block.trigger('mousedown')
|
|
|
|
const testTime = 330
|
|
|
|
await sleep(testTime)
|
|
|
|
block.trigger('mouseup')
|
|
|
|
const expectResult = Math.floor(testTime / 100)
|
|
|
|
expect(handler).toHaveBeenCalledTimes(expectResult)
|
|
|
|
})
|
|
|
|
})
|