forked from vuejs/vue-test-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTransitionStub.spec.js
107 lines (99 loc) · 2.83 KB
/
TransitionStub.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import ComponentWithTransition from '~resources/components/component-with-transition.vue'
import { describeWithShallowAndMount, vueVersion } from '~resources/utils'
import { TransitionStub } from '~vue/test-utils'
import { itDoNotRunIf } from 'conditional-specs'
describeWithShallowAndMount('TransitionStub', mountingMethod => {
let consoleError
beforeEach(() => {
consoleError = sinon.stub(console, 'error')
})
afterEach(() => {
consoleError.restore()
})
it('update synchronously when used as stubs for Transition', () => {
const wrapper = mountingMethod(ComponentWithTransition, {
stubs: {
transition: TransitionStub
}
})
expect(wrapper.text()).contains('a')
wrapper.setData({ a: 'b' })
expect(wrapper.text()).contains('b')
})
itDoNotRunIf(
vueVersion < 2.5,
'does not stub Transition, but applies synchronously in Vue > 2.5.18',
() => {
const wrapper = mountingMethod(ComponentWithTransition)
expect(wrapper.find(TransitionStub).exists()).to.equal(false)
expect(wrapper.text()).contains('a')
wrapper.setData({ a: 'b' })
expect(wrapper.text()).contains('b')
}
)
it('does not add v-leave class to children', () => {
const TestComponent = {
template: `
<div>
<transition name="expand">
<nav v-show="isShown" />
</transition>
<button @click="isShown = !isShown" />
</div>
`,
data: () => ({
isShown: false
})
}
const wrapper = mountingMethod(TestComponent, {
stubs: {
transition: TransitionStub
}
})
expect(wrapper.find('nav').isVisible()).to.equal(false)
wrapper.find('button').trigger('click')
expect(wrapper.find('nav').isVisible()).to.equal(true)
wrapper.find('button').trigger('click')
expect(wrapper.find('nav').isVisible()).to.equal(false)
})
it('logs error when has multiple children', () => {
const TestComponent = {
template: `
<transition><div /><div /></transition>
`
}
const msg =
'[vue-test-utils]: <transition> can only be used on a single element. Use <transition-group> for lists.'
mountingMethod(TestComponent, {
stubs: {
transition: TransitionStub
}
})
expect(consoleError).calledWith(msg)
})
it('handles keyed transitions', () => {
const TestComponent = {
template: `
<div>
<transition>
<div v-if="bool" key="a">a</div>
<div v-else key="b">b</div>
</transition>
</div>
`,
data() {
return {
bool: true
}
}
}
const wrapper = mountingMethod(TestComponent, {
stubs: {
transition: TransitionStub
}
})
expect(wrapper.text()).to.equal('a')
wrapper.setData({ bool: false })
expect(wrapper.text()).to.equal('b')
})
})