title: How to write Unit test in angular for testing routing code inside subscribe block
body: <p>I am new to unit testing in jasmine and karma for angular, here I am trying to test the router navigation, here we have a service to which some data is sent and inside the subscribe block I am navigating to a link,</p>
  <p>For this how can I write a unit test.</p>
  <p>CODE FOR THE FUNCTION INSIDE TS FILE.</p>
  <pre><code>onAction(action) {
     
      if (action == true) {
          this.data.action = action;
          this.data.loggedInId = this.id;
          this.Formservice.formMethod(this.data).subscribe(() =&gt; {
          this.router.navigate([`/${this.breadCrum}`]);
      });
      }
     }
  </code></pre>
  <p>CODE FOR THE SPEC.TS FILE</p>
  <pre><code>it(&quot;Check the router navigate after onAction&quot;,fakeAsync(()=&gt; {        
          component.onAction(true)
          flushMicrotasks()
          tick(10)
          fixture.detectChanges()
          tick(10)
          expect (mockRouter.navigate).toHaveBeenCalledWith ('/action-taken');
      }));
  </code></pre>
  <p>STEPS I FOLLOWED TO CREATE MOCK ROUTER SERVICE</p>
  <pre><code>import { Routes, RouterModule, ActivatedRoute, Router } from '@angular/router';
  
  let mockRouter = {
      navigate: jasmine.createSpy('navigate')
    }
  
  providers:[
  { provide: Router, useValue: mockRouter}
  ]
  </code></pre>
  <p>Here am I getting the error of <strong>Cannot read property of 'subscribe' of undefined</strong></p>