element-plus/packages/directives/__tests__/repeat-click.test.ts
三咲智子 1d13ebb05d
feat: drop jest (#7248)
* feat: drop jest

* test: remove ssr

* test: rename

* chore: update tsconfig
2022-04-19 16:51:44 +08:00

38 lines
870 B
TypeScript

import { mount } from '@vue/test-utils'
import { beforeEach, describe, expect, test, vi } from 'vitest'
import sleep from '@element-plus/test-utils/sleep'
import RepeatClick from '../repeat-click'
const handler = vi.fn()
const _mount = () =>
mount({
template: `
<div id="block" v-repeat-click="onClick">TEST</div>
`,
directives: {
repeatClick: RepeatClick,
},
methods: {
onClick() {
handler()
},
},
})
beforeEach(() => {
handler.mockClear()
})
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)
})
})