forked from vuejs/vue-test-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlisteners.spec.js
64 lines (59 loc) · 1.42 KB
/
listeners.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
import { listenersSupported } from '~resources/utils'
import {
describeWithShallowAndMount,
isRunningPhantomJS,
vueVersion
} from '~resources/utils'
import { itDoNotRunIf } from 'conditional-specs'
describeWithShallowAndMount('options.listeners', mountingMethod => {
itDoNotRunIf(
isRunningPhantomJS || !listenersSupported,
'handles inherit listeners',
() => {
const aListener = () => {}
const wrapper = mountingMethod(
{
template: '<p :id="$listeners.aListener" />'
},
{
listeners: {
aListener
}
}
)
expect(wrapper.vm.$listeners.aListener.fns).to.equal(aListener)
}
)
itDoNotRunIf(
isRunningPhantomJS || !listenersSupported,
'passes listeners to functional components',
() => {
const TestComponent = {
render(h, ctx) {
ctx.listeners.aListener()
ctx.listeners.bListener()
return h('div')
},
functional: true
}
mountingMethod(TestComponent, {
context: {
on: {
bListener() {}
}
},
listeners: {
aListener() {}
}
})
}
)
itDoNotRunIf(
vueVersion < 2.5,
'defines listeners as empty object even when not passed',
() => {
const wrapper = mountingMethod({ template: '<p />' })
expect(wrapper.vm.$listeners).to.deep.equal({})
}
)
})