test(v-model): mutating an array or set checkbox value (#13974)
ci / test (push) Has been cancelled Details
ci / continuous-release (push) Has been cancelled Details
size data / upload (push) Has been cancelled Details

This commit is contained in:
skirtle 2025-10-09 03:16:11 +01:00 committed by GitHub
parent 2dbe30177f
commit 079010a38c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 48 additions and 0 deletions

View File

@ -5,6 +5,7 @@ import {
nextTick,
ref,
render,
vModelCheckbox,
vModelDynamic,
withDirectives,
} from '@vue/runtime-dom'
@ -1445,4 +1446,51 @@ describe('vModel', () => {
expect(inputNum1.value).toBe('1')
})
it(`should support mutating an array or set value for a checkbox`, async () => {
const component = defineComponent({
data() {
return { value: [] }
},
render() {
return [
withDirectives(
h('input', {
type: 'checkbox',
class: 'foo',
value: 'foo',
'onUpdate:modelValue': setValue.bind(this),
}),
[[vModelCheckbox, this.value]],
),
]
},
})
render(h(component), root)
const foo = root.querySelector('.foo')
const data = root._vnode.component.data
expect(foo.checked).toEqual(false)
data.value.push('foo')
await nextTick()
expect(foo.checked).toEqual(true)
data.value[0] = 'bar'
await nextTick()
expect(foo.checked).toEqual(false)
data.value = new Set()
await nextTick()
expect(foo.checked).toEqual(false)
data.value.add('foo')
await nextTick()
expect(foo.checked).toEqual(true)
data.value.delete('foo')
await nextTick()
expect(foo.checked).toEqual(false)
})
})