3

I am trying to write unit test for logout method:

logout(): Observable<boolean> {
    ...
    location.assign('/Login');
    ...
    return Observable.of(false);
}

When karma getting line location.assign('/Login'); test result page moving away and writing 'NOT FOUND'.

I was trying to use spyOn:

spyOn(location,'assign').and.callFake(()=> true);

But getting error:

Error: <spyOn> : assign is not declared writable or has no setter

How to mock or disable location.assign method for unit test run?

  • here's the article how to do this https://medium.com/@sergeyfetiskin/testing-browser-window-location-in-angular-application-e4e8388508ff – s-f May 11 '18 at 12:02

0 Answers0