Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

feat(ngMock): invoke nested calls to module immediately #12887

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/ngMock/angular-mocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -2282,16 +2282,21 @@ if (window.jasmine || window.mocha) {
if (currentSpec.$injector) {
throw new Error('Injector already created, can not register a module!');
} else {
var modules = currentSpec.$modules || (currentSpec.$modules = []);
var fn, modules = currentSpec.$modules || (currentSpec.$modules = []);
angular.forEach(moduleFns, function(module) {
if (angular.isObject(module) && !angular.isArray(module)) {
modules.push(function($provide) {
fn = function($provide) {
angular.forEach(module, function(value, key) {
$provide.value(key, value);
});
});
};
} else {
modules.push(module);
fn = module;
}
if (currentSpec.$providerInjector) {
currentSpec.$providerInjector.invoke(fn);
} else {
modules.push(fn);
}
});
}
Expand Down Expand Up @@ -2405,6 +2410,9 @@ if (window.jasmine || window.mocha) {
function workFn() {
var modules = currentSpec.$modules || [];
var strictDi = !!currentSpec.$injectorStrict;
modules.unshift(function($injector) {
currentSpec.$providerInjector = $injector;
});
modules.unshift('ngMock');
modules.unshift('ng');
var injector = currentSpec.$injector;
Expand Down
13 changes: 13 additions & 0 deletions test/ngMock/angular-mocksSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,19 @@ describe('ngMock', function() {
});
});

describe('nested calls', function() {
it('should invoke nested module calls immediately', function() {
module(function($provide) {
$provide.constant('someConst', 'blah');
module(function(someConst) {
log = someConst;
});
});
inject(function() {
expect(log).toBe('blah');
});
});
});

describe('inline in test', function() {
it('should load module', function() {
Expand Down