dimanche 4 janvier 2015

Angular UI-Router verify onEnter in test

I am in the middle of writing some tests for my application (AngularJS). As we speak I encountered a problem with verifying if onEnter property of my state was called correctly.


Let me share some 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 failing assertion is the last one I am trying to verify therefore mentioned onEnter. Error is:


Error: [$injector:unpr] Unknown provider: actionModelProvider <- actionModel http://ift.tt/13Se6sU$injector/unpr?p0=actionModelProvider%20%3C-%20actionModel


As it is expected Angular tries to resolve actionModel which is the property from the resolve.


I dont know what I might be doing wrong here, so any help will be gladly welcomed.


I am attaching the state configuration as well:



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'
}
}
}
}
}
);

Aucun commentaire:

Enregistrer un commentaire