Skip to content

Commit f31366c

Browse files
committed
add tests for some :class and v-bind edge cases
1 parent 682a840 commit f31366c

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

test/unit/features/directives/bind.spec.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,4 +199,27 @@ describe('Directive v-bind', () => {
199199
}).$mount()
200200
expect('v-bind without argument expects an Object or Array value').toHaveBeenWarned()
201201
})
202+
203+
// a vdom patch edge case where the user has several un-keyed elements of the
204+
// same tag next to each other, and toggling them.
205+
it('properly update for toggling un-keyed children', done => {
206+
const vm = new Vue({
207+
template: `
208+
<div>
209+
<div v-if="ok" id="a" data-test="1"></div>
210+
<div v-if="!ok" id="b"></div>
211+
</div>
212+
`,
213+
data: {
214+
ok: true
215+
}
216+
}).$mount()
217+
expect(vm.$el.children[0].id).toBe('a')
218+
expect(vm.$el.children[0].getAttribute('data-test')).toBe('1')
219+
vm.ok = false
220+
waitForUpdate(() => {
221+
expect(vm.$el.children[0].id).toBe('b')
222+
expect(vm.$el.children[0].getAttribute('data-test')).toBe(null)
223+
}).then(done)
224+
})
202225
})

test/unit/features/directives/class.spec.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,25 @@ describe('Directive v-bind:class', () => {
106106
expect(vm.$el.className).toBe('a b')
107107
}).then(done)
108108
})
109+
110+
// a vdom patch edge case where the user has several un-keyed elements of the
111+
// same tag next to each other, and toggling them.
112+
it('properly remove staticClass for toggling un-keyed children', done => {
113+
const vm = new Vue({
114+
template: `
115+
<div>
116+
<div v-if="ok" class="a"></div>
117+
<div v-if="!ok"></div>
118+
</div>
119+
`,
120+
data: {
121+
ok: true
122+
}
123+
}).$mount()
124+
expect(vm.$el.children[0].className).toBe('a')
125+
vm.ok = false
126+
waitForUpdate(() => {
127+
expect(vm.$el.children[0].className).toBe('')
128+
}).then(done)
129+
})
109130
})

0 commit comments

Comments
 (0)