【问题标题】:Error: Could not resolve 'app.history' from state ' '错误:无法从状态“”解析“app.history”
【发布时间】:2015-04-28 16:13:32
【问题描述】:

我正在编写使用 $stateProvider 的单元测试(代码及其测试文件的代码如下所示)。执行此操作时,它给出错误-“错误:无法解析 'app.历史'来自状态''”。

$stateProvider
    .state('app',       
     {   
        url: "/app",    
        templateUrl: "pages/app/index.html",
        controller: function($state)    {
        $state.go('app.history');
    }})
    .state('app.history', 
         { url: "/history", 
           templateUrl: "pages/app/modules/History/partials/history.html"
          })

单元测试代码-

describe("Unit tests for config.jst", function() {
  var $rootScope, $injector, $state;
  beforeEach(module('ui.router'));

  beforeEach(inject(function(_$rootScope_, _$state_, _$injector_, $templateCache) {
    $rootScope = _$rootScope_;
    $injector = _$injector_;
    $state = _$state_;

    $templateCache.put("pages/app/index.html", "");
    $templateCache.put("pages/app/modules/History/partials/history.html", "");
}));

describe("states", function() {
    var state = "app.history";
    it("verify state configuration", function() {
        //var config = $state.get(state);
        $state.go(state);
        $rootScope.$digest();
        //console.log($state);
        expect($state.current.name).to.be.equal(state);
    });
 });
});

【问题讨论】:

    标签: angularjs unit-testing mocha.js chai


    【解决方案1】:

    您忘记包含应用程序模块。

    添加

    module('your_application_module_name');

    下面

    beforeEach(module('ui.router'));

    【讨论】:

      猜你喜欢
      • 2015-10-03
      • 1970-01-01
      • 1970-01-01
      • 2015-03-31
      • 1970-01-01
      • 2017-08-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多