title: Angular - Router unit testing with testing module and RouterMock
body: <p>I've read several questions about how to unit test routing. But nothing fits my case really. I have a navbar-comp. with several <code>[routerLink]=[...]</code>
  And when I simulate a click event. I want for instance to call <code>expect(router.navigate).toHaveBeenCalledWith(*path*);</code></p>
  
  <p>But I am already failing on the test setup: It throws me everytime a: <code>cannot find root of undefined</code>.</p>
  
  <h2>Test suite</h2>
  
  <pre><code>describe('NavbarComponent', () =&gt; {
    let component: NavbarComponent;
    let fixture: ComponentFixture&lt;NavbarComponent&gt;;
  
    const router: Router = jasmine.createSpyObj('Router', ['navigate']);
  
    beforeEach(async(() =&gt; {
      TestBed.configureTestingModule({
        imports: [
          NgbModule.forRoot(),
          RouterTestingModule
        ],
        providers: [
          {provide: Router, useValue: router}
        ],
        declarations: [
          NavbarComponent,
        ]
      })
        .compileComponents();
    }));
  
    it('should navigate on click - home', () =&gt; {
      (&lt;jasmine.Spy&gt;router.navigate).and.stub();
      const debugElm = fixture.debugElement.nativeElement.querySelector('#navLogo');
      debugElm.click();
  
      expect(router.navigate).toHaveBeenCalledWith(['/stories']);
    });
  </code></pre>
  
  <p>When I delete the <code>RoutingTestingModule</code> import then it throws me: <code>Cannot bind to routerLink</code> - which I actually need to test. Really frustrating... Does anyone has a solution for this? </p>