From 898714df9ea38f9ef700015ced5ddea52f096b77 Mon Sep 17 00:00:00 2001 From: Shahar Talmi Date: Wed, 4 Feb 2015 22:42:04 +0200 Subject: [PATCH] fix(ngMock): handle cases where injector is created before tests This caused an exception for people who created an injector before the tests actually began to run. Since the array was initialized only in beforeEach, anyone accessing it before that would throw. This is solved easily but initializing the array immediately. Closes #10967 --- src/ngMock/angular-mocks.js | 2 +- test/ngMock/angular-mocksSpec.js | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/ngMock/angular-mocks.js b/src/ngMock/angular-mocks.js index 9d010b4ab9c6..dcefe12008ca 100644 --- a/src/ngMock/angular-mocks.js +++ b/src/ngMock/angular-mocks.js @@ -2131,7 +2131,7 @@ angular.mock.$RootScopeDecorator = ['$delegate', function($delegate) { if (window.jasmine || window.mocha) { var currentSpec = null, - annotatedFunctions, + annotatedFunctions = [], isSpecRunning = function() { return !!currentSpec; }; diff --git a/test/ngMock/angular-mocksSpec.js b/test/ngMock/angular-mocksSpec.js index 78cb1e268736..104ece1c0aa5 100644 --- a/test/ngMock/angular-mocksSpec.js +++ b/test/ngMock/angular-mocksSpec.js @@ -1813,3 +1813,10 @@ describe('ngMockE2E', function() { }); }); }); + +describe('make sure that we can create an injector outside of tests', function() { + //since some libraries create custom injectors outside of tests, + //we want to make sure that this is not breaking the internals of + //how we manage annotated function cleanup during tests. See #10967 + angular.injector([function($injector) {}]); +});