Skip to content

Commit 898714d

Browse files
committed
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 angular#10967
1 parent 966f6d8 commit 898714d

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/ngMock/angular-mocks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2131,7 +2131,7 @@ angular.mock.$RootScopeDecorator = ['$delegate', function($delegate) {
21312131
if (window.jasmine || window.mocha) {
21322132

21332133
var currentSpec = null,
2134-
annotatedFunctions,
2134+
annotatedFunctions = [],
21352135
isSpecRunning = function() {
21362136
return !!currentSpec;
21372137
};

test/ngMock/angular-mocksSpec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1813,3 +1813,10 @@ describe('ngMockE2E', function() {
18131813
});
18141814
});
18151815
});
1816+
1817+
describe('make sure that we can create an injector outside of tests', function() {
1818+
//since some libraries create custom injectors outside of tests,
1819+
//we want to make sure that this is not breaking the internals of
1820+
//how we manage annotated function cleanup during tests. See #10967
1821+
angular.injector([function($injector) {}]);
1822+
});

0 commit comments

Comments
 (0)