I have created a window.location.reload
function in my javascript.
I need to mock the reload function while testing in Jasmine since it keeps on looping.
The test goes well when I run grunt jenkins
. But not while testing in the browser (mozilla/chrome).
Here is my code snippet.
Javascript:
window.location.reload();
Jasmine Test:
spyOn(window.location, 'reload').and.callFake(function(){});
Can anyone please help me on this?
window.location.reload
is not a writable property, so the browser won't let a spy override it. To get around this, see https://mcmap.net/q/275528/-jasmine-mock-window-object – Sheridan