forked from bootstrap-vue/bootstrap-vue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlisten-on-root.spec.js
77 lines (62 loc) · 1.88 KB
/
listen-on-root.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { mount } from '@vue/test-utils'
import { listenOnRootMixin } from './listen-on-root'
describe('mixins/listen-on-root', () => {
it('works', async () => {
const spyOn = jest.fn()
const spyOnce = jest.fn()
const TestComponent = {
mixins: [listenOnRootMixin],
created() {
this.listenOnRoot('root-on', spyOn)
this.listenOnRootOnce('root-once', spyOnce)
},
render(h) {
return h('div', this.$slots.default)
}
}
const App = {
components: { TestComponent },
props: {
destroy: {
type: Boolean,
default: false
}
},
render(h) {
return h('div', [this.destroy ? h() : h(TestComponent, 'test-component')])
}
}
const wrapper = mount(App, {
propsData: {
destroy: false
}
})
expect(wrapper.vm).toBeDefined()
expect(wrapper.text()).toEqual('test-component')
expect(spyOn).not.toHaveBeenCalled()
expect(spyOnce).not.toHaveBeenCalled()
const $root = wrapper.vm.$root
$root.$emit('root-on')
expect(spyOn).toHaveBeenCalledTimes(1)
expect(spyOnce).not.toHaveBeenCalled()
$root.$emit('root-once')
expect(spyOn).toHaveBeenCalledTimes(1)
expect(spyOnce).toHaveBeenCalledTimes(1)
$root.$emit('root-on')
expect(spyOn).toHaveBeenCalledTimes(2)
expect(spyOnce).toHaveBeenCalledTimes(1)
$root.$emit('root-once')
expect(spyOn).toHaveBeenCalledTimes(2)
expect(spyOnce).toHaveBeenCalledTimes(1)
await wrapper.setProps({ destroy: true })
expect(spyOn).toHaveBeenCalledTimes(2)
expect(spyOnce).toHaveBeenCalledTimes(1)
$root.$emit('root-on')
expect(spyOn).toHaveBeenCalledTimes(2)
expect(spyOnce).toHaveBeenCalledTimes(1)
$root.$emit('root-once')
expect(spyOn).toHaveBeenCalledTimes(2)
expect(spyOnce).toHaveBeenCalledTimes(1)
wrapper.destroy()
})
})