2020-09-16 14:49:21 +08:00
|
|
|
import { mount } from '@vue/test-utils'
|
2021-09-17 15:27:31 +08:00
|
|
|
import { sleep } from '@element-plus/test-utils'
|
2020-09-16 14:49:21 +08:00
|
|
|
import RepeatClick from '../repeat-click'
|
|
|
|
|
|
|
|
const handler = jest.fn()
|
2021-09-04 19:29:28 +08:00
|
|
|
const _mount = () =>
|
|
|
|
mount({
|
|
|
|
template: `
|
2020-09-16 14:49:21 +08:00
|
|
|
<div id="block" v-repeat-click="onClick">TEST</div>
|
|
|
|
`,
|
2021-09-04 19:29:28 +08:00
|
|
|
directives: {
|
|
|
|
repeatClick: RepeatClick,
|
2020-09-16 14:49:21 +08:00
|
|
|
},
|
2021-09-04 19:29:28 +08:00
|
|
|
methods: {
|
|
|
|
onClick() {
|
|
|
|
handler()
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
2020-09-16 14:49:21 +08:00
|
|
|
|
|
|
|
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)
|
|
|
|
})
|
|
|
|
})
|