title: How to unit-test a function that calls window.location.href in Angular2
body: <p>I have this function I need to test:</p>
  
  <pre><code>login(): void {
      this.userService.setSessionAndDateOnlogin();
      this.loginService.getLogin()
        .subscribe(
          octopusUrl =&gt; window.location.href = octopusUrl);
    }
  </code></pre>
  
  <p>I use the window.location.href to navigate to an external URL.</p>
  
  <p>This is my test:</p>
  
  <pre><code>it('login function should call the setSessionAndDateOnLogin function from the userservice and\
     subscribe to the  getLogin function of the loginService.',
      fakeAsync(
        inject(
          [LoginComponent, LoginService, UserService],
          (loginComponent: LoginComponent, loginService: LoginService, userService: UserService) =&gt; {
            spyOn(userService, 'setSessionAndDateOnlogin');
            loginComponent.login();
            expect(userService.setSessionAndDateOnlogin).toHaveBeenCalled();
          })
      )
    );
  </code></pre>
  
  <p>When I run this test, I get the following error:</p>
  
  <blockquote>
    <p>Some of your tests did a full page reload!</p>
  </blockquote>
  
  <p>So I tried to mock the window-object:</p>
  
  <pre><code>import { window } from '@angular/platform-browser/src/facade/browser';
  ...
  class MockWindow {
    location: {
      href: ''
    };
  }
  ...
  beforeEach(() =&gt; addProviders([
      ...
      { provide: window, useClass: MockWindow }
    ]));
  </code></pre>
  
  <p>This changed nothing and the error remains.</p>
  
  <p>Does anyone has a solution for this issue?</p>