forked from bootstrap-vue/bootstrap-vue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclick-out.spec.js
52 lines (45 loc) · 1.28 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
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 = {
mixins: [clickOutMixin],
// `listenForClickOut` comes from the mixin data
created() {
this.listenForClickOut = true
},
methods: {
clickOutHandler() {
count++
}
},
render(h) {
return h('div', [h('button', 'button')])
}
}
const wrapper = mount(App, {
attachTo: document.body
})
const clickEvent = 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)
await wrapper.find('button').trigger('click')
expect(count).toBe(0)
await wrapper.trigger('click')
expect(count).toBe(0)
document.dispatchEvent(clickEvent)
await waitNT(wrapper.vm)
expect(count).toBe(1)
// When `this.listenForClickOut` is `false`
await wrapper.setData({ listenForClickOut: false })
document.dispatchEvent(clickEvent)
await waitNT(wrapper.vm)
expect(count).toBe(1)
wrapper.destroy()
})
})