nextTick,
Ref,
readonly,
- reactive
+ reactive,
+ defineComponent
} from '../src/index'
import { render, nodeOps, serialize } from '@vue/runtime-test'
expect(serialize(root)).toBe(`<div>foobar</div>`)
})
+ it('bound to instance', () => {
+ const Provider = {
+ setup() {
+ return () => h(Consumer)
+ }
+ }
+
+ const Consumer = defineComponent({
+ name: 'Consumer',
+ inject: {
+ foo: {
+ from: 'foo',
+ default() {
+ return this!.$options.name
+ }
+ }
+ },
+ render() {
+ // @ts-ignore
+ return this.foo
+ }
+ })
+
+ const root = nodeOps.createElement('div')
+ render(h(Provider), root)
+ expect(serialize(root)).toBe(`<div>Consumer</div>`)
+ })
+
it('nested providers', () => {
const ProviderOne = {
setup() {
return provides[key as string]
} else if (arguments.length > 1) {
return treatDefaultAsFactory && isFunction(defaultValue)
- ? defaultValue()
+ ? defaultValue.call(instance.proxy)
: defaultValue
} else if (__DEV__) {
warn(`injection "${String(key)}" not found.`)