fix(runtime-core): ensure declare prop keys are always present
fix #3288
This commit is contained in:
@@ -11,7 +11,8 @@ import {
|
||||
createApp,
|
||||
provide,
|
||||
inject,
|
||||
watch
|
||||
watch,
|
||||
toRefs
|
||||
} from '@vue/runtime-test'
|
||||
import { render as domRender, nextTick } from 'vue'
|
||||
|
||||
@@ -479,4 +480,32 @@ describe('component props', () => {
|
||||
expect(serializeInner(root)).toMatch(`<h1>11</h1>`)
|
||||
expect(count).toBe(0)
|
||||
})
|
||||
|
||||
// #3288
|
||||
test('declared prop key should be present even if not passed', async () => {
|
||||
let initialKeys: string[] = []
|
||||
const changeSpy = jest.fn()
|
||||
const passFoo = ref(false)
|
||||
|
||||
const Comp = {
|
||||
render() {},
|
||||
props: {
|
||||
foo: String
|
||||
},
|
||||
setup(props: any) {
|
||||
initialKeys = Object.keys(props)
|
||||
const { foo } = toRefs(props)
|
||||
watch(foo, changeSpy)
|
||||
}
|
||||
}
|
||||
|
||||
const Parent = () => (passFoo.value ? h(Comp, { foo: 'ok' }) : h(Comp))
|
||||
const root = nodeOps.createElement('div')
|
||||
createApp(Parent).mount(root)
|
||||
|
||||
expect(initialKeys).toMatchObject(['foo'])
|
||||
passFoo.value = true
|
||||
await nextTick()
|
||||
expect(changeSpy).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user