From 85afbbe9a45fa54f818b8b0f0d8f17c136344d09 Mon Sep 17 00:00:00 2001 From: Rahul Kadyan Date: Wed, 1 Mar 2017 14:36:06 +0530 Subject: [PATCH 1/2] Check property exists instead of truthy value --- src/core/instance/inject.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/instance/inject.js b/src/core/instance/inject.js index 2b1fd7f0274..0c55b42a629 100644 --- a/src/core/instance/inject.js +++ b/src/core/instance/inject.js @@ -25,7 +25,7 @@ export function initInjections (vm: Component) { const provideKey = isArray ? key : inject[key] let source = vm while (source) { - if (source._provided && source._provided[provideKey]) { + if (source._provided && provideKey in source._provided) { vm[key] = source._provided[provideKey] break } From 6ea789fa1044658c3970f7f40965d28099509654 Mon Sep 17 00:00:00 2001 From: Rahul Kadyan Date: Wed, 1 Mar 2017 15:29:42 +0530 Subject: [PATCH 2/2] Provide some falsy values for inject tests --- test/unit/features/options/inject.spec.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/test/unit/features/options/inject.spec.js b/test/unit/features/options/inject.spec.js index a80734bca79..500d3aed607 100644 --- a/test/unit/features/options/inject.spec.js +++ b/test/unit/features/options/inject.spec.js @@ -20,7 +20,7 @@ describe('Options provide/inject', () => { template: ``, provide: { foo: 1, - bar: 2 + bar: false }, components: { child: { @@ -32,7 +32,7 @@ describe('Options provide/inject', () => { } }).$mount() - expect(injected).toEqual([1, 2]) + expect(injected).toEqual([1, false]) }) it('should use closest parent', () => { @@ -40,7 +40,7 @@ describe('Options provide/inject', () => { template: ``, provide: { foo: 1, - bar: 2 + bar: null }, components: { child: { @@ -55,7 +55,7 @@ describe('Options provide/inject', () => { } }).$mount() - expect(injected).toEqual([3, 2]) + expect(injected).toEqual([3, null]) }) it('provide function', () => { @@ -63,7 +63,7 @@ describe('Options provide/inject', () => { template: ``, data: { a: 1, - b: 2 + b: false }, provide () { return { @@ -81,7 +81,7 @@ describe('Options provide/inject', () => { } }).$mount() - expect(injected).toEqual([1, 2]) + expect(injected).toEqual([1, false]) }) it('inject with alias', () => { @@ -99,7 +99,7 @@ describe('Options provide/inject', () => { new Vue({ template: ``, provide: { - foo: 1, + foo: false, bar: 2 }, components: { @@ -112,7 +112,7 @@ describe('Options provide/inject', () => { } }).$mount() - expect(injected).toEqual([1, 2]) + expect(injected).toEqual([false, 2]) }) it('self-inject', () => {