fix(runtime-core): v-model listeners that already exists on the component should not be merged (#2011)
fix #1989
This commit is contained in:
@@ -594,4 +594,61 @@ describe('attribute fallthrough', () => {
|
||||
button.dispatchEvent(new CustomEvent('click'))
|
||||
expect(click).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
// #1989
|
||||
it('should not fallthrough v-model listeners with corresponding declared prop', () => {
|
||||
let textFoo = ''
|
||||
let textBar = ''
|
||||
const click = jest.fn()
|
||||
|
||||
const App = defineComponent({
|
||||
setup() {
|
||||
return () =>
|
||||
h(Child, {
|
||||
modelValue: textFoo,
|
||||
'onUpdate:modelValue': (val: string) => {
|
||||
textFoo = val
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
const Child = defineComponent({
|
||||
props: ['modelValue'],
|
||||
setup(_props, { emit }) {
|
||||
return () =>
|
||||
h(GrandChild, {
|
||||
modelValue: textBar,
|
||||
'onUpdate:modelValue': (val: string) => {
|
||||
textBar = val
|
||||
emit('update:modelValue', 'from Child')
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
const GrandChild = defineComponent({
|
||||
props: ['modelValue'],
|
||||
setup(_props, { emit }) {
|
||||
return () =>
|
||||
h('button', {
|
||||
onClick() {
|
||||
click()
|
||||
emit('update:modelValue', 'from GrandChild')
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
const root = document.createElement('div')
|
||||
document.body.appendChild(root)
|
||||
render(h(App), root)
|
||||
|
||||
const node = root.children[0] as HTMLElement
|
||||
|
||||
node.dispatchEvent(new CustomEvent('click'))
|
||||
expect(click).toHaveBeenCalled()
|
||||
expect(textBar).toBe('from GrandChild')
|
||||
expect(textFoo).toBe('from Child')
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user