Skip to content

Commit 997ab5d

Browse files
committed
test: v-model checkbox array model
1 parent 0626af6 commit 997ab5d

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

test/unit/specs/directives/model_spec.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,50 @@ if (_.inBrowser) {
221221
})
222222
})
223223

224+
it('checkbox + array model', function (done) {
225+
var vm = new Vue({
226+
el: el,
227+
data: {
228+
list: [1],
229+
a: {}
230+
},
231+
template:
232+
'<input type="checkbox" v-model="list" number value="1">' +
233+
'<input type="checkbox" v-model="list" :value="a">'
234+
})
235+
expect(el.firstChild.checked).toBe(true)
236+
expect(el.lastChild.checked).toBe(false)
237+
el.firstChild.click()
238+
expect(vm.list.length).toBe(0)
239+
el.lastChild.click()
240+
expect(vm.list.length).toBe(1)
241+
expect(vm.list[0]).toBe(vm.a)
242+
el.firstChild.click()
243+
expect(vm.list.length).toBe(2)
244+
expect(vm.list[1]).toBe(1)
245+
vm.list = [vm.a]
246+
_.nextTick(function () {
247+
expect(el.firstChild.checked).toBe(false)
248+
expect(el.lastChild.checked).toBe(true)
249+
done()
250+
})
251+
})
252+
253+
it('checkbox + array model default value', function () {
254+
var vm = new Vue({
255+
el: el,
256+
data: {
257+
list: [],
258+
a: {}
259+
},
260+
template:
261+
'<input type="checkbox" v-model="list" number value="1">' +
262+
'<input type="checkbox" checked v-model="list" :value="a">'
263+
})
264+
expect(vm.list.length).toBe(1)
265+
expect(vm.list[0]).toBe(vm.a)
266+
})
267+
224268
it('select', function (done) {
225269
var vm = new Vue({
226270
el: el,

0 commit comments

Comments
 (0)