Skip to content

Commit

Permalink
fix(v-model): fix trim modifier on events with non-string args ( (vue…
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowings-zy authored and chrislone committed Feb 4, 2023
1 parent 1a2fb93 commit 08e5991
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
22 changes: 22 additions & 0 deletions packages/runtime-core/__tests__/componentEmits.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,28 @@ describe('component: emit', () => {
expect(fn2).toHaveBeenCalledTimes(1)
expect(fn2).toHaveBeenCalledWith(1)
})

test('only trim string parameter when work with v-model on component', () => {
const Foo = defineComponent({
render() {},
created() {
this.$emit('update:modelValue', ' foo ', { bar: ' bar ' })
}
})

const fn = jest.fn()
const Comp = () =>
h(Foo, {
modelValue: null,
modelModifiers: { trim: true },
'onUpdate:modelValue': fn
})

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

expect(fn).toHaveBeenCalledTimes(1)
expect(fn).toHaveBeenCalledWith('foo', { bar: ' bar ' })
})

test('isEmitListener', () => {
const options = {
Expand Down
3 changes: 2 additions & 1 deletion packages/runtime-core/src/componentEmits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
isArray,
isFunction,
isObject,
isString,
isOn,
toNumber,
UnionToIntersection
Expand Down Expand Up @@ -122,7 +123,7 @@ export function emit(
}Modifiers`
const { number, trim } = props[modifiersKey] || EMPTY_OBJ
if (trim) {
args = rawArgs.map(a => a.trim())
args = rawArgs.map(a => isString(a) ? a.trim() : a)
}
if (number) {
args = rawArgs.map(toNumber)
Expand Down

0 comments on commit 08e5991

Please sign in to comment.