fix(runtime-core): v-model listeners that already exists on the component should not be merged (#2011)

fix #1989
This commit is contained in:
HcySunYang
2020-09-02 10:24:20 +08:00
committed by GitHub
parent aa757e8e6d
commit 63f1f18064
2 changed files with 70 additions and 7 deletions

View File

@@ -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')
})
})