test(runtime-dom): add test for vModel composition session (#1631)

This commit is contained in:
learningMaster 2020-07-21 22:34:08 +08:00 committed by GitHub
parent 3e412c10e0
commit 324167d3d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -604,4 +604,45 @@ describe('vModel', () => {
expect(foo.selected).toEqual(true)
expect(bar.selected).toEqual(true)
})
it('should work with composition session', async () => {
const component = defineComponent({
data() {
return { value: '' }
},
render() {
return [
withVModel(
h('input', {
'onUpdate:modelValue': setValue.bind(this)
}),
this.value
)
]
}
})
render(h(component), root)
const input = root.querySelector('input')!
const data = root._vnode.component.data
expect(input.value).toEqual('')
//developer.mozilla.org/en-US/docs/Web/API/Element/compositionstart_event
//compositionstart event could be fired after a user starts entering a Chinese character using a Pinyin IME
input.value = '使用拼音'
triggerEvent('compositionstart', input)
await nextTick()
expect(data.value).toEqual('')
// input event has no effect during composition session
input.value = '使用拼音输入'
triggerEvent('input', input)
await nextTick()
expect(data.value).toEqual('')
// After compositionend event being fired, an input event will be automatically trigger
triggerEvent('compositionend', input)
await nextTick()
expect(data.value).toEqual('使用拼音输入')
})
})