Angular UI-Router验证onEnter in test

kor*_*ter 6 javascript unit-testing angularjs karma-runner angular-ui-router

我正在为我的应用程序(AngularJS)编写一些测试.正如我们所说,我遇到了验证我的状态的onEnter属性是否被正确调用的问题.

让我与你分享一些代码

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

 });
Run Code Online (Sandbox Code Playgroud)

失败的断言是我试图验证的最后一个因此在onEnter中提到的.错误是:

错误:[$ injector:unpr]未知提供者:actionModelProvider < - actionModel http://errors.angularjs.org/1.3.8/ $ injector/unpr?p0 = actionModelProvider%20%3C-%20actionModel

正如预期角度试图解决actionModel这是从属性的决心.

我不知道我在这里做错了什么,所以欢迎任何帮助.

我也附加状态配置:

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'
                    }
                }
            }
        }
    }
);
Run Code Online (Sandbox Code Playgroud)