【发布时间】:2015-02-11 04:53:09
【问题描述】:
我有这么简单的sn-p代码(真实app代码比较复杂),重点是测试$state.includes
$scope.Testing (state) {
if (!$state.includes(state)){
$state.go(state);
}
}
在单元测试中,我需要将当前状态设置为要测试的状态的子状态:
spyOn($state,"go");
$state.current.name = "app.subState";//set current state
$scope.Testing("app");
expect($state.go).not.toHaveBeenCalled();
但$state.go 仍然被调用。在我看来,设置 $state.current.name 没有效果。然后我尝试了:
spyOn($state,"go");
$state.transitionTo("app.subState");//set current state.
$scope.Testing("app");
expect($state.go).not.toHaveBeenCalled();
但看起来 $state.transitionTo 会触发真正的 http 请求并最终出现如下错误:Error: Unexpected request: GET /state.html
谢谢。
【问题讨论】:
标签: angularjs unit-testing jasmine angular-ui-router