mirror of https://github.com/vuejs/core.git
test(v-model): mutating an array or set checkbox value (#13974)
This commit is contained in:
parent
2dbe30177f
commit
079010a38c
|
@ -5,6 +5,7 @@ import {
|
||||||
nextTick,
|
nextTick,
|
||||||
ref,
|
ref,
|
||||||
render,
|
render,
|
||||||
|
vModelCheckbox,
|
||||||
vModelDynamic,
|
vModelDynamic,
|
||||||
withDirectives,
|
withDirectives,
|
||||||
} from '@vue/runtime-dom'
|
} from '@vue/runtime-dom'
|
||||||
|
@ -1445,4 +1446,51 @@ describe('vModel', () => {
|
||||||
|
|
||||||
expect(inputNum1.value).toBe('1')
|
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)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue