parent
93a950d60d
commit
3056e9b3dc
@ -70,6 +70,37 @@ describe('vModel', () => {
|
||||
expect(input.value).toEqual('')
|
||||
})
|
||||
|
||||
it('should work with number input', async () => {
|
||||
const component = defineComponent({
|
||||
data() {
|
||||
return { value: null }
|
||||
},
|
||||
render() {
|
||||
return [
|
||||
withVModel(
|
||||
h('input', {
|
||||
type: 'number',
|
||||
'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('')
|
||||
expect(input.type).toEqual('number')
|
||||
|
||||
input.value = 1
|
||||
triggerEvent('input', input)
|
||||
await nextTick()
|
||||
expect(typeof data.value).toEqual('number')
|
||||
expect(data.value).toEqual(1)
|
||||
})
|
||||
|
||||
it('should work with multiple listeners', async () => {
|
||||
const spy = jest.fn()
|
||||
const component = defineComponent({
|
||||
|
@ -49,7 +49,8 @@ export const vModelText: ModelDirective<
|
||||
> = {
|
||||
created(el, { modifiers: { lazy, trim, number } }, vnode) {
|
||||
el._assign = getModelAssigner(vnode)
|
||||
const castToNumber = number || el.type === 'number'
|
||||
const castToNumber =
|
||||
number || (vnode.props && vnode.props.type === 'number')
|
||||
addEventListener(el, lazy ? 'change' : 'input', e => {
|
||||
if ((e.target as any).composing) return
|
||||
let domValue: string | number = el.value
|
||||
|
Loading…
Reference in New Issue
Block a user