Angular UI-Router check onEnter in test

I am in the middle of writing some tests for my application (AngularJS). When we say, I had a problem checking the validity of the onEnter property of my state.

Let me share the code with you

describe('Midway :: routesTest', function () { var $state, $rootScope, $injector, navigationService; beforeEach(function () { module('springatom', function ($provide) { $provide.value('navigationService', navigationService = {}); }); states.configure(); inject(function (_$rootScope_, _$state_, _$injector_, $templateCache) { $rootScope = _$rootScope_; $state = _$state_; $injector = _$injector_; // We need add the template entry into the templateCache if we ever // specify a templateUrl $templateCache.put('/static/sa/views/home/home.html', ''); $templateCache.put('/static/sa/tpls/grid.html', ''); }); navigationService.getNavigationModel = jasmine.createSpy('getNavigationModel').and.returnValue([]); navigationService.setNavigatorModel = jasmine.createSpy('setNavigatorModel').and.callFake(function (arg) { }); }); it("should have a working home route", inject(function () { var homeState = $state.get('home'); expect(homeState).toBeDefined(); expect($state.href(homeState)).toEqual('#/sa'); $rootScope.$apply(function () { $state.go(homeState); }); var current = $state.current; expect($injector.invoke(current.resolve.actionModel)).toEqual([]); expect($injector.invoke(current.onEnter)).toHaveBeenCalled(); })); }); 

The unsuccessful statement is the last one I am trying to verify, therefore the onEnter mentioned. Error:

Error: [$ injector: unpr] Unknown provider: actionModelProvider <- actionModel http://errors.angularjs.org/1.3.8/ $ injector / unpr? p0 = actionModelProvider% 20% 3C-% 20actionModel

As expected, Angular is trying to allow actionModel , which is a property of allow .

I do not know what I can do wrong here, so any help will be gladly received.

I also add state configuration:

 define( [ 'views/home/homeController', 'views/home/recentlyUpdatedController', // angular deps 'services/navigation' ], function homeState(homeController, recentlyUpdatedController) { return { name : 'home', definition: { url : '/sa', templateUrl: '/static/sa/views/home/home.html', resolve : { actionModel: function (navigationService) { return navigationService.getNavigationModel('main.navigation') } }, onEnter : function (actionModel, navigationService) { navigationService.setNavigatorModel('main.navigation'); }, views : { '': { controller : recentlyUpdatedController, templateUrl: '/static/sa/tpls/grid.html' } } } } } ); 
+5
source share

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


All Articles