var refresh = function(){
console.info("refreshing page")
window.location.reload();
}
我应该监视上面的函数“window.location.reload()”
我已经给出了代码
describe('for page refresh',function(){
spyOn(window.location,'reload');
it('should refresh the welcome page',function(){
expect($location.reload),toHaveBeenCalled();
引发错误 错误::重新加载未声明为可写或没有 setter 。
我是 angularJS 的新手。任何帮助都会非常有用。
最佳答案
我也是 Jasmine 的新手。检查一下,它可能对您有帮助。
describe('for page refresh', function() {
beforeEach(function() {
refresh = {
reload: function(value) {
window.location.reload();
}
};
spyOn(refresh, 'reload');
});
it('should refresh the welcome page', function() {
refresh.reload();
expect(refresh.reload).toHaveBeenCalled();
});
})
关于angularjs - 如何监视 AngularJS 中的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43910833/