title: Mocking router.events.subscribe() Angular2
body: <p>In my app.component.ts I have the following ngOnInit function:</p>
  
  <pre><code>ngOnInit() {
      this.sub = this.router.events.subscribe(e =&gt; {
        if (e instanceof NavigationEnd) {
          if (!e.url.includes('login')) {
            this.loggedIn = true;
          } else {
            this.loggedIn = false;
          }
        }
      });
    }
  </code></pre>
  
  <p>Currently I'm testing if the sub is not null but I want to test the function with a 100% coverage.</p>
  
  <p>I want to mock the router object so that I can simulate the URL and then test if the this.loggedIn is correctly set.</p>
  
  <p>How would I proceed to mock this function? I tried it but I don't know how I would take this on with the callback involved and with the NavigationEnd.</p>