在我的 ctrl 中,我有这段代码可以在函数完成工作后导航到页面。
$scope.myFunction = function(){
//other code
window.location.assign(url);
}
我的测试代码如下所示。
describe('TEST', function () {
var window;
beforeEach(module(function($provide) {
//dummy window
window = {
location:{href:function(){return 'dummy'},assign:function()
{return 'dummy1'}}
};
// We register our new $window instead of the old
$provide.constant('$window',window);
}));
it("should test",function(){
$scope.myfunction();
});
});
The error that I get is ..Some of your tests did a full page reload! and the test fails.
我已经关注了此处记录的问题(单元测试 AngularJS $window 服务),但同样的方法对我不起作用。任何想法?