diff --git a/src/core/instance/inject.js b/src/core/instance/inject.js
index 4ee76319..0afd3c81 100644
--- a/src/core/instance/inject.js
+++ b/src/core/instance/inject.js
@@ -1,7 +1,6 @@
/* @flow */
import { warn } from '../util/index'
-import { hasOwn } from 'shared/util'
import { hasSymbol } from 'core/util/env'
import { defineReactive, observerState } from '../observer/index'
@@ -56,7 +55,7 @@ export function resolveInject (inject: any, vm: Component): ?Object {
}
source = source.$parent
}
- if (process.env.NODE_ENV !== 'production' && !hasOwn(result, key)) {
+ if (process.env.NODE_ENV !== 'production' && !source) {
warn(`Injection "${key}" not found`, vm)
}
}
diff --git a/src/core/util/options.js b/src/core/util/options.js
index 899a2575..465bb628 100644
--- a/src/core/util/options.js
+++ b/src/core/util/options.js
@@ -201,11 +201,10 @@ strats.props =
strats.methods =
strats.inject =
strats.computed = function (parentVal: ?Object, childVal: ?Object): ?Object {
- if (!childVal) return Object.create(parentVal || null)
if (!parentVal) return childVal
const ret = Object.create(null)
extend(ret, parentVal)
- extend(ret, childVal)
+ if (childVal) extend(ret, childVal)
return ret
}
strats.provide = mergeDataOrFn
diff --git a/test/unit/features/options/inject.spec.js b/test/unit/features/options/inject.spec.js
index ba95d949..d501cd02 100644
--- a/test/unit/features/options/inject.spec.js
+++ b/test/unit/features/options/inject.spec.js
@@ -250,6 +250,68 @@ describe('Options provide/inject', () => {
expect(injected).toEqual([1, false])
})
+ it('should merge from mixins properly (objects)', () => {
+ const mixinA = { inject: { foo: 'foo' }}
+ const mixinB = { inject: { bar: 'bar' }}
+ const child = {
+ mixins: [mixinA, mixinB],
+ template: ``,
+ created () {
+ injected = [this.foo, this.bar]
+ }
+ }
+ new Vue({
+ provide: { foo: 'foo', bar: 'bar', baz: 'baz' },
+ render (h) {
+ return h(child)
+ }
+ }).$mount()
+
+ expect(injected).toEqual(['foo', 'bar'])
+ })
+
+ it('should merge from mixins properly (arrays)', () => {
+ const mixinA = { inject: ['foo'] }
+ const mixinB = { inject: ['bar'] }
+ const child = {
+ mixins: [mixinA, mixinB],
+ inject: ['baz'],
+ template: ``,
+ created () {
+ injected = [this.foo, this.bar, this.baz]
+ }
+ }
+ new Vue({
+ provide: { foo: 'foo', bar: 'bar', baz: 'baz' },
+ render (h) {
+ return h(child)
+ }
+ }).$mount()
+
+ expect(injected).toEqual(['foo', 'bar', 'baz'])
+ })
+
+ it('should merge from mixins properly (mix of objects and arrays)', () => {
+ const mixinA = { inject: { foo: 'foo' }}
+ const mixinB = { inject: ['bar'] }
+ const child = {
+ mixins: [mixinA, mixinB],
+ inject: { qux: 'baz' },
+ template: ``,
+ created () {
+ injected = [this.foo, this.bar, this.qux]
+ }
+ }
+ new Vue({
+ provide: { foo: 'foo', bar: 'bar', baz: 'baz' },
+ render (h) {
+ return h(child)
+ }
+ }).$mount()
+
+ expect(injected).toEqual(['foo', 'bar', 'baz'])
+ })
+
it('should warn when injections has been modified', () => {
const key = 'foo'
const vm = new Vue({