Skip to content

Commit 6782d10

Browse files
committed
test: v-model checkbox array model
1 parent f38fbc3 commit 6782d10

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

test/unit/specs/directives/public/model_spec.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,50 @@ if (_.inBrowser) {
167167
})
168168
})
169169

170+
it('checkbox + array model', function (done) {
171+
var vm = new Vue({
172+
el: el,
173+
data: {
174+
list: [1],
175+
a: {}
176+
},
177+
template:
178+
'<input type="checkbox" v-model="list" number value="1">' +
179+
'<input type="checkbox" v-model="list" :value="a">'
180+
})
181+
expect(el.firstChild.checked).toBe(true)
182+
expect(el.lastChild.checked).toBe(false)
183+
el.firstChild.click()
184+
expect(vm.list.length).toBe(0)
185+
el.lastChild.click()
186+
expect(vm.list.length).toBe(1)
187+
expect(vm.list[0]).toBe(vm.a)
188+
el.firstChild.click()
189+
expect(vm.list.length).toBe(2)
190+
expect(vm.list[1]).toBe(1)
191+
vm.list = [vm.a]
192+
_.nextTick(function () {
193+
expect(el.firstChild.checked).toBe(false)
194+
expect(el.lastChild.checked).toBe(true)
195+
done()
196+
})
197+
})
198+
199+
it('checkbox + array model default value', function () {
200+
var vm = new Vue({
201+
el: el,
202+
data: {
203+
list: [],
204+
a: {}
205+
},
206+
template:
207+
'<input type="checkbox" v-model="list" number value="1">' +
208+
'<input type="checkbox" checked v-model="list" :value="a">'
209+
})
210+
expect(vm.list.length).toBe(1)
211+
expect(vm.list[0]).toBe(vm.a)
212+
})
213+
170214
it('select', function (done) {
171215
var vm = new Vue({
172216
el: el,

0 commit comments

Comments
 (0)