Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(runtime-core): only trim string parameter when work with v-model on component (#5765) #5770

Merged
merged 2 commits into from Oct 26, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 22 additions & 0 deletions packages/runtime-core/__tests__/componentEmits.spec.ts
Expand Up @@ -355,6 +355,28 @@ describe('component: emit', () => {
expect(fn2).toHaveBeenCalledWith('two')
})

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 = {
click: null,
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-core/src/componentEmits.ts
Expand Up @@ -121,7 +121,7 @@ export function emit(
}Modifiers`
const { number, trim } = props[modifiersKey] || EMPTY_OBJ
if (trim) {
args = rawArgs.map(a => a.trim())
args = rawArgs.map(a => (typeof a === 'string' ? a.trim() : a))
} else if (number) {
args = rawArgs.map(toNumber)
}
Expand Down