2014-05-15 27 views
1

我试图单元测试ui.router嵌套的状态和正在以下错误:单元测试UI路由器嵌套国

Error: Could not resolve 'client_view.notes' from state '' 

我知道这件事情做,我怎么设置状态&范围在测试之前。有人可以填补我吗?

路由:

.state('client_view', { 
    url: '/client/{id}', 
    templateUrl: 'static/templates/client.tpl.html', 
    controller: 'ClientController' 
}) 
.state('client_view.notes', { 
    url: '/notes', 
    templateUrl: 'static/templates/client_notes.tpl.html', 
    controller: 'ClientNotesController', 
    parent: 'client_view' 
}) 

测试:

$scope = $rootScope.$new(); 
client_controller = $controller('ClientController', { 
    $scope: $scope, 
    $state: $state 
}); 
$rootScope.$apply(function() { 
    $state.go('client_view.notes'); 
}); 
expect($scope.active('notes')).toEqual(true); 

$scope.active是我写的是存在于ClientController的方法。如果设置正确,测试将通过。

谢谢!

回答

-1

我一直在等待穿过这条路线测试自己的桥梁。所以我不知道如何处理这种情况,但我可以尝试推测。

由于规格不必须获得来自国家的全貌,也许你可以使用

$state.current 

在应用$ state.go之前设置当前状态 - 但是这仅仅是猜测 - 为错误是说我不知道​​我来自哪里。

Error: Could not resolve 'client_view.notes' from state '' 

状态配置api