Skip to content

Commit

Permalink
fix(runtime-dom): add test for #5839
Browse files Browse the repository at this point in the history
  • Loading branch information
liulinboyi committed May 2, 2022
1 parent bd22aa8 commit b002cee
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
31 changes: 31 additions & 0 deletions packages/runtime-core/__tests__/componentEmits.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,37 @@ describe('component: emit', () => {
expect(fn2).toHaveBeenCalledWith('two')
})

test('.trim and .number modifiers should work with v-model on component', () => {
const Foo = defineComponent({
render() {},
created() {
this.$emit('update:modelValue', ' +01.2 ')
this.$emit('update:foo', ' 1 ')
}
})

const fn1 = jest.fn()
const fn2 = jest.fn()

const Comp = () =>
h(Foo, {
modelValue: null,
modelModifiers: { trim: true, number: true },
'onUpdate:modelValue': fn1,

foo: null,
fooModifiers: { trim: true, number: true },
'onUpdate:foo': fn2
})

render(h(Comp), nodeOps.createElement('div'))

expect(fn1).toHaveBeenCalledTimes(1)
expect(fn1).toHaveBeenCalledWith(1.2)
expect(fn2).toHaveBeenCalledTimes(1)
expect(fn2).toHaveBeenCalledWith(1)
})

test('isEmitListener', () => {
const options = {
click: null,
Expand Down
26 changes: 25 additions & 1 deletion packages/runtime-dom/__tests__/directives/vModel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ describe('vModel', () => {
it('should support modifiers', async () => {
const component = defineComponent({
data() {
return { number: null, trim: null, lazy: null }
return { number: null, trim: null, lazy: null, trimNumber: null }
},
render() {
return [
Expand Down Expand Up @@ -229,6 +229,19 @@ describe('vModel', () => {
trim: true
}
),
withVModel(
h('input', {
class: 'trim-number',
'onUpdate:modelValue': (val: any) => {
this.trimNumber = val
}
}),
this.trimNumber,
{
trim: true,
number: true
}
),
withVModel(
h('input', {
class: 'lazy',
Expand All @@ -248,6 +261,7 @@ describe('vModel', () => {

const number = root.querySelector('.number')
const trim = root.querySelector('.trim')
const trimNumber = root.querySelector('.trim-number')
const lazy = root.querySelector('.lazy')
const data = root._vnode.component.data

Expand All @@ -261,6 +275,16 @@ describe('vModel', () => {
await nextTick()
expect(data.trim).toEqual('hello, world')

trimNumber.value = ' 1 '
triggerEvent('input', trimNumber)
await nextTick()
expect(data.trimNumber).toEqual(1)

trimNumber.value = ' +01.2 '
triggerEvent('input', trimNumber)
await nextTick()
expect(data.trimNumber).toEqual(1.2)

lazy.value = 'foo'
triggerEvent('change', lazy)
await nextTick()
Expand Down

0 comments on commit b002cee

Please sign in to comment.