小编kor*_*ter的帖子

Angular UI-Router验证onEnter in test

我正在为我的应用程序(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 …
Run Code Online (Sandbox Code Playgroud)

javascript unit-testing angularjs karma-runner angular-ui-router

6
推荐指数
0
解决办法
571
查看次数