test: add testcase

This commit is contained in:
yangchangtao 2024-11-18 17:37:17 +08:00
parent 030553eb63
commit 4ff9ca74f6
1 changed files with 46 additions and 0 deletions

View File

@ -1,5 +1,6 @@
import {
type VNode,
computed,
defineComponent,
h,
nextTick,
@ -1409,6 +1410,51 @@ describe('vModel', () => {
expect(bar.selected).toEqual(true)
})
it('multiple select (v-model has custom setter)', async () => {
const selected = ref([])
const multipleSelected = computed({
get() {
return selected.value
},
set(newVal) {
selected.value = newVal.slice(0, 1)
},
})
const setValue = (v: any) => {
multipleSelected.value = v
}
const component = defineComponent({
render() {
return [
withVModel(
h(
'select',
{
multiple: true,
'onUpdate:modelValue': setValue,
},
[h('option', { value: '1' }), h('option', { value: '2' })],
),
multipleSelected.value,
),
]
},
})
render(h(component), root)
await nextTick()
const select = root.querySelector('select')
const [foo, bar] = root.querySelectorAll('option')
foo.selected = true
bar.selected = true
triggerEvent('change', select)
await nextTick()
expect(selected.value).toEqual(['1'])
expect(foo.selected).toEqual(true)
expect(bar.selected).toEqual(false)
})
// #10503
test('equal value with a leading 0 should trigger update.', async () => {
const setNum = function (this: any, value: any) {