Skip to content

Commit 324167d

Browse files
authored
test(runtime-dom): add test for vModel composition session (#1631)
1 parent 3e412c1 commit 324167d

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

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

+41
Original file line numberDiff line numberDiff line change
@@ -604,4 +604,45 @@ describe('vModel', () => {
604604
expect(foo.selected).toEqual(true)
605605
expect(bar.selected).toEqual(true)
606606
})
607+
608+
it('should work with composition session', async () => {
609+
const component = defineComponent({
610+
data() {
611+
return { value: '' }
612+
},
613+
render() {
614+
return [
615+
withVModel(
616+
h('input', {
617+
'onUpdate:modelValue': setValue.bind(this)
618+
}),
619+
this.value
620+
)
621+
]
622+
}
623+
})
624+
render(h(component), root)
625+
626+
const input = root.querySelector('input')!
627+
const data = root._vnode.component.data
628+
expect(input.value).toEqual('')
629+
630+
//developer.mozilla.org/en-US/docs/Web/API/Element/compositionstart_event
631+
//compositionstart event could be fired after a user starts entering a Chinese character using a Pinyin IME
632+
input.value = '使用拼音'
633+
triggerEvent('compositionstart', input)
634+
await nextTick()
635+
expect(data.value).toEqual('')
636+
637+
// input event has no effect during composition session
638+
input.value = '使用拼音输入'
639+
triggerEvent('input', input)
640+
await nextTick()
641+
expect(data.value).toEqual('')
642+
643+
// After compositionend event being fired, an input event will be automatically trigger
644+
triggerEvent('compositionend', input)
645+
await nextTick()
646+
expect(data.value).toEqual('使用拼音输入')
647+
})
607648
})

0 commit comments

Comments
 (0)