-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
/
Copy pathshow.spec.ts
114 lines (108 loc) · 3.21 KB
/
show.spec.ts
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
108
109
110
111
112
113
114
import Vue from 'vue'
describe('Directive v-show', () => {
it('should check show value is truthy', () => {
const vm = new Vue({
template: '<div><span v-show="foo">hello</span></div>',
data: { foo: true }
}).$mount()
expect(vm.$el.firstChild.style.display).toBe('')
})
it('should check show value is falsy', () => {
const vm = new Vue({
template: '<div><span v-show="foo">hello</span></div>',
data: { foo: false }
}).$mount()
expect(vm.$el.firstChild.style.display).toBe('none')
})
it('should update show value changed', done => {
const vm = new Vue({
template: '<div><span v-show="foo">hello</span></div>',
data: { foo: true }
}).$mount()
expect(vm.$el.firstChild.style.display).toBe('')
vm.foo = false
waitForUpdate(() => {
expect(vm.$el.firstChild.style.display).toBe('none')
vm.foo = {}
})
.then(() => {
expect(vm.$el.firstChild.style.display).toBe('')
vm.foo = 0
})
.then(() => {
expect(vm.$el.firstChild.style.display).toBe('none')
vm.foo = []
})
.then(() => {
expect(vm.$el.firstChild.style.display).toBe('')
vm.foo = null
})
.then(() => {
expect(vm.$el.firstChild.style.display).toBe('none')
vm.foo = '0'
})
.then(() => {
expect(vm.$el.firstChild.style.display).toBe('')
vm.foo = undefined
})
.then(() => {
expect(vm.$el.firstChild.style.display).toBe('none')
vm.foo = 1
})
.then(() => {
expect(vm.$el.firstChild.style.display).toBe('')
})
.then(done)
})
it('should respect display value in style attribute', done => {
const vm = new Vue({
template:
'<div><span v-show="foo" style="display:block">hello</span></div>',
data: { foo: true }
}).$mount()
expect(vm.$el.firstChild.style.display).toBe('block')
vm.foo = false
waitForUpdate(() => {
expect(vm.$el.firstChild.style.display).toBe('none')
vm.foo = true
})
.then(() => {
expect(vm.$el.firstChild.style.display).toBe('block')
})
.then(done)
})
it('should support unbind when reused', done => {
const vm = new Vue({
template:
'<div v-if="tester"><span v-show="false"></span></div>' +
'<div v-else><span @click="tester=!tester">show</span></div>',
data: { tester: true }
}).$mount()
expect(vm.$el.firstChild.style.display).toBe('none')
vm.tester = false
waitForUpdate(() => {
expect(vm.$el.firstChild.style.display).toBe('')
vm.tester = true
})
.then(() => {
expect(vm.$el.firstChild.style.display).toBe('none')
})
.then(done)
})
it('should prefer to use v-show to update display', done => {
const vm = new Vue({
template: '<div v-show="display" :style="style">{{ count }}</div>',
data: { display: false, count: 1, style: { display: 'block' } }
}).$mount()
expect(vm.$el.style.display).toBe('none')
vm.count++
waitForUpdate(() => {
expect(vm.$el.style.display).toBe('none')
vm.display = true
})
.then(() => {
expect(vm.$el.style.display).toBe('block')
})
.then(done)
})
})