In my angular project, I have a function
reloadPage(): void {
window.location.reload();
}
So when ever I need to reload the page, I used to call this function.
Now I am trying to add the unit testing for this function but it is not working.
it("reloadPage: should be validated", () => {
spyOn(window.location, 'reload').and.callFake(() => {
//test
});
component.reloadPage();
});
It still reloads the page on unit testing
How can I achieve a unit test for this function? Any help could be appreciated. Thanks in advance
reload
method with a spy?window.location.reload = jasmine.spy()
. Don't forget to restore the reload method after the test run – Luanneluanni