test(runtime-dom): add test for vModel composition session (#1631)
This commit is contained in:
parent
3e412c10e0
commit
324167d3d2
@ -604,4 +604,45 @@ describe('vModel', () => {
|
|||||||
expect(foo.selected).toEqual(true)
|
expect(foo.selected).toEqual(true)
|
||||||
expect(bar.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('使用拼音输入')
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user