feat(runtime-core): support using inject() inside props default functions
This commit is contained in:
@@ -8,7 +8,9 @@ import {
|
||||
defineComponent,
|
||||
ref,
|
||||
serializeInner,
|
||||
createApp
|
||||
createApp,
|
||||
provide,
|
||||
inject
|
||||
} from '@vue/runtime-test'
|
||||
import { render as domRender, nextTick } from 'vue'
|
||||
|
||||
@@ -212,6 +214,32 @@ describe('component props', () => {
|
||||
expect(defaultFn).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
test('using inject in default value factory', () => {
|
||||
const Child = defineComponent({
|
||||
props: {
|
||||
test: {
|
||||
default: () => inject('test', 'default')
|
||||
}
|
||||
},
|
||||
setup(props) {
|
||||
return () => {
|
||||
return h('div', props.test)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const Comp = {
|
||||
setup() {
|
||||
provide('test', 'injected')
|
||||
return () => h(Child)
|
||||
}
|
||||
}
|
||||
|
||||
const root = nodeOps.createElement('div')
|
||||
render(h(Comp), root)
|
||||
expect(serializeInner(root)).toBe(`<div>injected</div>`)
|
||||
})
|
||||
|
||||
test('optimized props updates', async () => {
|
||||
const Child = defineComponent({
|
||||
props: ['foo'],
|
||||
|
||||
Reference in New Issue
Block a user