defineComponent,
ref,
serializeInner,
- createApp
+ createApp,
+ provide,
+ inject
} from '@vue/runtime-test'
import { render as domRender, nextTick } from 'vue'
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'],
Data,
ComponentInternalInstance,
ComponentOptions,
- ConcreteComponent
+ ConcreteComponent,
+ setCurrentInstance
} from './component'
import { isEmitListener } from './componentEmits'
import { InternalObjectKey } from './vnode'
options,
rawCurrentProps,
camelizedKey,
- value
+ value,
+ instance
)
}
} else {
options,
rawProps || EMPTY_OBJ,
key,
- undefined
+ undefined,
+ instance
)
}
} else {
options!,
rawCurrentProps,
key,
- rawCurrentProps[key]
+ rawCurrentProps[key],
+ instance
)
}
}
options: NormalizedProps,
props: Data,
key: string,
- value: unknown
+ value: unknown,
+ instance: ComponentInternalInstance
) {
const opt = options[key]
if (opt != null) {
// default values
if (hasDefault && value === undefined) {
const defaultValue = opt.default
- value =
- opt.type !== Function && isFunction(defaultValue)
- ? defaultValue(props)
- : defaultValue
+ if (opt.type !== Function && isFunction(defaultValue)) {
+ setCurrentInstance(instance)
+ value = defaultValue(props)
+ setCurrentInstance(null)
+ } else {
+ value = defaultValue
+ }
}
// boolean casting
if (opt[BooleanFlags.shouldCast]) {