How to taunt with configuration providers for unit tests?

I am writing a specification that verifies that a method is called during the configuration phase of the Angular module under test.

Here's a simplified look at the code under test:

angular.module('core',['services.configAction'])
    .config(function(configAction){
        configAction.deferIntercept(true);
    });

What happens above, we define a module corethat has one dependency.
Then, in the configmodule block, corewe call the method deferInterceptfor the object configActionspecified for use from services.configAction.

I am trying to verify that this coreconfig calls this method.

This is the current setting:

describe('core',function()
{
    const configActionProvider={
        deferIntercept:jasmine.createSpy('deferIntercept'),
        $get:function(){
            return {/*...*/}
        }
    };

    beforeEach(function()
    {
        module(function($provide)
        {
            $provide.provider('configAction',configActionProvider);
        });

        module('core.AppInitializer');

        inject(function($injector)
        {
            //...
        });
    });

    it('should call deferIntercept',function()
    {
        expect(configActionProvider.deferIntercept).toHaveBeenCalledWith(true);
    });
});

, configAction, , -. , core, angular.module('core',[]) angular.module('core',['services.configAction']) spy.

services.configAction , ?

+4
1

https://dzone.com/articles/unit-testing-config-and-run. - -

module('services.configAction', function (configAction) {
  mockConfigAction = configAction;
  spyOn(mockConfigAction, 'deferIntercept').andCallThrough();
});
module('core');

beforeEach .

+5

Source: https://habr.com/ru/post/1618890/


All Articles