forked from bootstrap-vue/bootstrap-vue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclick-out.spec.js
55 lines (48 loc) · 1.29 KB
/
click-out.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import Vue from 'vue'
import { mount } from '@vue/test-utils'
import { waitNT } from '../../tests/utils'
import clickOutMixin from './click-out'
describe('utils/click-out', () => {
it('works', async () => {
let count = 0
const App = Vue.extend({
mixins: [clickOutMixin],
// listenForClickOut comes from the mixin data
created() {
this.listenForClickOut = true
},
methods: {
clickOutHandler(evt) {
count++
}
},
render(h) {
return h('div', {}, [h('button', {}, 'button')])
}
})
const wrapper = mount(App, {
attachToDocument: true
})
const clickEvt = new MouseEvent('click')
expect(wrapper).toBeDefined()
expect(count).toBe(0)
expect(wrapper.vm.listenForClickOut).toBe(true)
// When this.listenForClickOut is true
expect(count).toBe(0)
wrapper.find('button').trigger('click')
expect(count).toBe(0)
wrapper.trigger('click')
expect(count).toBe(0)
document.dispatchEvent(clickEvt)
await waitNT(wrapper.vm)
expect(count).toBe(1)
// When this.listenForClickOut is false
wrapper.setData({
listenForClickOut: false
})
document.dispatchEvent(clickEvt)
await waitNT(wrapper.vm)
expect(count).toBe(1)
wrapper.destroy()
})
})