expect(serialize(root)).toBe(`<div><!----></div>`)
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()
+ })
})
if (key in provides) {
// TS doesn't allow symbol as index type
return provides[key as string]
- } else if (defaultValue !== undefined) {
+ } else if (arguments.length > 1) {
return defaultValue
} else if (__DEV__) {
warn(`injection "${String(key)}" not found.`)