forked from vuejs/vue-test-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlisteners.spec.js
62 lines (57 loc) · 1.49 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
import { compileToFunctions } from 'vue-template-compiler'
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(
compileToFunctions('<p :id="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(compileToFunctions('<p />'))
expect(wrapper.vm.$listeners).to.deep.equal({})
}
)
})