I am facing the following problem.

I have an angular 1.5 project with many modules and each module may depend on 
other modules. 

Trying to unit test say a controller which is part of a module I would do 
import the module like this


angular.mock.module('SaidModule');


then provide and inject its services where needed.


the problem is that SaidModule depends on AnotherModule1, AnotherModule2, 
AnotherModule3


angular.module('SaidModule', ['AnotherModule1', 'AnotherModule2', 
'AnotherModule3'])



So naturally when I call SaidModule the other modules are also invoked which is 
out of scope in terms of Unit testing


In the unit test I have tried the following solution


angular.module('AnotherModule1',[])
angular.module('AnotherModule2',[])
angular.module('AnotherModule3',[])
angular.mock.module('SaidModule')



and although for the current unit test I have successfully decoupled the 
dependencies I have also destroyed 

the actual AnotherModule1, AnotherModule2, AnotherModule3 so when its there 
turn to be unit tested they are

not even visible in the angular project which seems correct to me. as I am 
using angular.module to define a 

new module which just happens to override the actual module. 

This solution though is also suggested here mocking module dependencies 
<https://www.sitepoint.com/mocking-dependencies-angularjs-tests/>


In the angular docs it states see angular docs mock module 
<https://docs.angularjs.org/api/ngMock/function/angular.mock.module>

If an object literal is passed each key-value pair will be registered on the 
module via $provide 
<https://docs.angularjs.org/api/auto/service/$provide>.value, 
the key being the string name (or token) to associate with the value on the 
injector.

So it seems to me that the solution is using somehow angular.mock.module 
somehow to override the dependent 

modules but so far I have not found a solution. 

Any help much appreciated

-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to