From b4ead6e76d375af4b3c66b000418ede1f279a14d Mon Sep 17 00:00:00 2001 From: Martin Probst Date: Tue, 7 Jul 2015 10:43:32 +0200 Subject: [PATCH] fix(injector): check that modulesToLoad isArray. When users accidentally just pass a single string, e.g. `angular.injector('myModule')`, this change give them a better error message. Currently Angular just reports that the module with the name 'm' is missing, as it's iterating through all characters in the string, instead of all strings in the module. --- src/auto/injector.js | 1 + test/auto/injectorSpec.js | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/src/auto/injector.js b/src/auto/injector.js index f6980a67140..303348f5ee6 100644 --- a/src/auto/injector.js +++ b/src/auto/injector.js @@ -718,6 +718,7 @@ function createInjector(modulesToLoad, strictDi) { // Module Loading //////////////////////////////////// function loadModules(modulesToLoad) { + assertArg(isUndefined(modulesToLoad) || isArray(modulesToLoad), 'modulesToLoad', 'not an array'); var runBlocks = [], moduleFn; forEach(modulesToLoad, function(module) { if (loadedModules.get(module)) return; diff --git a/test/auto/injectorSpec.js b/test/auto/injectorSpec.js index cff2ec5b0e7..391082e28a2 100644 --- a/test/auto/injectorSpec.js +++ b/test/auto/injectorSpec.js @@ -35,6 +35,12 @@ describe('injector', function() { }); + it('should check its modulesToLoad argument', function() { + expect(function() { angular.injector('test'); }) + .toThrowMinErr('ng', 'areq'); + }); + + it('should resolve dependency graph and instantiate all services just once', function() { var log = [];