How to test Angular service module without starting the run and config?

If the module is set to the " run " function (with dependencies), then to test one service this module is necessary either to load all dependencies of that module, or to replace them.
How to avoid it?
September 19th 19 at 00:26
1 answer
September 19th 19 at 00:28
I think You have a slightly incorrect view of testing. Your options are "either to load or to replace" is the answer to Your question.
If Your test service is a helper object, and it is already covered by tests, use mock objects (substitution). In another case, if the service is the key point of the module, it must be downloaded "as is" and to verify his methods including.
Apparently the question should not sound like. As for Jasmine + Angular.To Mock service to unit test so that you can samokat all the dependencies of this service, but not to load the entire module at the same time (specifically run and config).

Now use
var Service1;
beforeEach(inject((_Service1_) => {
Service1 = _Service1_;

When it's run and run and config. But I for unit testing, they do not need. - xzavier commented on September 19th 19 at 00:31
Run config and if they are declared probably can't be omitted and will therefore be running anyway. You can samokat through providers based on, for example
beforeEach(module('Module1', function($provide) {
 $provide.value('$window', {
 alert: jasmine.createSpy('alert')

Then Your problem with the substitution all dependencies will be resolved. Hope I understood correctly... - oral_Lindgren64 commented on September 19th 19 at 00:34
: Yes, it turns out the God-object, these run and config. In run can be transferred to the dependencies for the whole module for all its functions. Moka all for unit test one service, which even 1% of these dependencies do not need... - xzavier commented on September 19th 19 at 00:37
: mmm, why not break this module into submodules with the logic of run and config, so when testing to take only a single module with the desired services?
There probably is not God-object, but rather a feature of the life cycle of AngularJS. - oral_Lindgren64 commented on September 19th 19 at 00:40

Find more questions by tags AngularDevelopment through testing