parent
573bcb2e11
commit
94562daea7
@ -284,4 +284,27 @@ describe('api: provide/inject', () => {
|
|||||||
expect(serialize(root)).toBe(`<div><!----></div>`)
|
expect(serialize(root)).toBe(`<div><!----></div>`)
|
||||||
expect(`injection "foo" not found.`).toHaveBeenWarned()
|
expect(`injection "foo" not found.`).toHaveBeenWarned()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should not warn when default value is undefined', () => {
|
||||||
|
const Provider = {
|
||||||
|
setup() {
|
||||||
|
return () => h(Middle)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const Middle = {
|
||||||
|
render: () => h(Consumer)
|
||||||
|
}
|
||||||
|
|
||||||
|
const Consumer = {
|
||||||
|
setup() {
|
||||||
|
const foo = inject('foo', undefined)
|
||||||
|
return () => foo
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const root = nodeOps.createElement('div')
|
||||||
|
render(h(Provider), root)
|
||||||
|
expect(`injection "foo" not found.`).not.toHaveBeenWarned()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
@ -40,7 +40,7 @@ export function inject(
|
|||||||
if (key in provides) {
|
if (key in provides) {
|
||||||
// TS doesn't allow symbol as index type
|
// TS doesn't allow symbol as index type
|
||||||
return provides[key as string]
|
return provides[key as string]
|
||||||
} else if (defaultValue !== undefined) {
|
} else if (arguments.length > 1) {
|
||||||
return defaultValue
|
return defaultValue
|
||||||
} else if (__DEV__) {
|
} else if (__DEV__) {
|
||||||
warn(`injection "${String(key)}" not found.`)
|
warn(`injection "${String(key)}" not found.`)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user