Skip to content

Commit 6354019

Browse files
committed
test(v-model): mutating an array or set checkbox value
1 parent c16f8a9 commit 6354019

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

packages/runtime-dom/__tests__/directives/vModel.spec.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
nextTick,
66
ref,
77
render,
8+
vModelCheckbox,
89
vModelDynamic,
910
withDirectives,
1011
} from '@vue/runtime-dom'
@@ -1445,4 +1446,51 @@ describe('vModel', () => {
14451446

14461447
expect(inputNum1.value).toBe('1')
14471448
})
1449+
1450+
it(`should support mutating an array or set value for a checkbox`, async () => {
1451+
const component = defineComponent({
1452+
data() {
1453+
return { value: [] }
1454+
},
1455+
render() {
1456+
return [
1457+
withDirectives(
1458+
h('input', {
1459+
type: 'checkbox',
1460+
class: 'foo',
1461+
value: 'foo',
1462+
'onUpdate:modelValue': setValue.bind(this),
1463+
}),
1464+
[[vModelCheckbox, this.value]],
1465+
),
1466+
]
1467+
},
1468+
})
1469+
render(h(component), root)
1470+
1471+
const foo = root.querySelector('.foo')
1472+
const data = root._vnode.component.data
1473+
1474+
expect(foo.checked).toEqual(false)
1475+
1476+
data.value.push('foo')
1477+
await nextTick()
1478+
expect(foo.checked).toEqual(true)
1479+
1480+
data.value[0] = 'bar'
1481+
await nextTick()
1482+
expect(foo.checked).toEqual(false)
1483+
1484+
data.value = new Set()
1485+
await nextTick()
1486+
expect(foo.checked).toEqual(false)
1487+
1488+
data.value.add('foo')
1489+
await nextTick()
1490+
expect(foo.checked).toEqual(true)
1491+
1492+
data.value.delete('foo')
1493+
await nextTick()
1494+
expect(foo.checked).toEqual(false)
1495+
})
14481496
})

0 commit comments

Comments
 (0)