我如何注入$ transition $来编写基于组件的路由的jasmine测试用例来测试解析对象?

时间:2017-04-14 06:41:35

标签: angularjs jasmine

我想为具有$ transition $作为依赖关系的resolve对象编写测试用例。 这是我的配置:

angular.module("testing")
  .config(function($stateProvider) {
    $stateProvider.state({
      name: 'component.view',
      url: '/:componentName',      
      resolve: {
        componentName: ($transition$) => $transition$.params().componentName        
      }
    });
});

所以我想用jasmine测试resolve对象。请建议我一个解决方案。提前谢谢。

1 个答案:

答案 0 :(得分:0)

得到了解决方案。我们可以通过创建提供商来解决这个问题这是:

beforeEach(module('testing', function ($provide) {
    $provide.provider("$transition$", function () {
          this.$get = function () {           
            return {
                'params':function(){
                    return {
                        'componentName':'Component one'
                    };
                }
            };
          }
    })
}));
相关问题