-
Notifications
You must be signed in to change notification settings - Fork 668
/
Copy pathupdate.spec.js
79 lines (72 loc) · 2.27 KB
/
update.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
import { compileToFunctions } from 'vue-template-compiler'
import ComponentWithVIf from '~resources/components/component-with-v-if.vue'
import { describeWithShallowAndMount } from '~resources/test-utils'
describeWithShallowAndMount('update', (mountingMethod) => {
it('causes vm to re render', () => {
const wrapper = mountingMethod(ComponentWithVIf)
expect(wrapper.findAll('.child.ready').length).to.equal(0)
wrapper.vm.$set(wrapper.vm, 'ready', true)
wrapper.update()
expect(wrapper.findAll('.child.ready').length).to.equal(1)
})
it('updates slot components', () => {
if (mountingMethod.name === 'shallow') return
const SlotComponent = compileToFunctions('<div><slot></slot></div>')
const Parent = {
template: `
<SlotComponent>
<div :class="[{ 'is-on': on }, 'inner']"></div>
</SlotComponent>
`,
props: {
on: {
default: false,
type: Boolean
}
},
components: {
SlotComponent
}
}
const parentWrapper = mountingMethod(Parent)
const innerEl = parentWrapper.find('.inner')
expect(innerEl.hasClass('is-on')).to.equal(false)
parentWrapper.setProps({
on: true
})
expect(innerEl.hasClass('is-on')).to.equal(true)
})
it('runs watchers', () => {
const TestComponent = {
template: `
<div>
<input v-model="text" />
<button v-if="showButton">Submit</button>
</div>
`,
data () {
return {
text: '',
showButton: false
}
},
watch: {
text () {
this.showButton = true
}
}
}
const wrapper = mountingMethod(TestComponent)
wrapper.find('input').element.value = 'Value'
wrapper.find('input').trigger('input')
expect(wrapper.vm.showButton).to.equal(true)
expect(wrapper.find('button').exists()).to.equal(true)
})
it('causes vm to re render, and retain slots', () => {
const compiled = compileToFunctions('<div><slot></slot></div>')
const wrapper = mountingMethod(compiled, { slots: { default: [compileToFunctions('<div class="test-div" />')] }})
expect(wrapper.findAll('.test-div').length).to.equal(1)
wrapper.update()
expect(wrapper.findAll('.test-div').length).to.equal(1)
})
})