I am using protractor and mocking the backend calls using http-backend-proxy. I login and it makes a call which I have mocked. I then clear the token in the local storage using
browser.executeScript( 'localStorage.clear();' );
And then I perform a browser.refresh() because I want it to redirect me back to the login screen so I can perform the next test.
My problem: When the refresh is performed, instead of taking me back to the login screen it attempts to make the call for that page again and fails saying it is an Unexpected GET request. It is because it is now returning a 401 Unauthorized response (since I cleared the token).
How can I handle intercepting the call when it is a 401 Unauthorized response or get it to redirect me back to the login in that instance?
Thanks!
Browser.refresh will call httpBackend.onLoad.when instead of httpBackend.when. Once I added the onLoad mocking/responses, it worked.