title: Angular 2 unit testing components with routerLink
body: <p>I am trying to test my component with angular 2 final, but I get an error because the component uses the <code>routerLink</code> directive. I get the following error:</p>
  
  <blockquote>
    <p>Can't bind to 'routerLink' since it isn't a known property of 'a'.</p>
  </blockquote>
  
  <p>This is the relevant code of the <code>ListComponent</code> template</p>
  
  <pre><code>&lt;a 
    *ngFor="let item of data.list" 
    class="box"
    routerLink="/settings/{{collectionName}}/edit/{{item._id}}"&gt;
  </code></pre>
  
  <p>And here is my test.</p>
  
  <pre><code>import { TestBed } from '@angular/core/testing';
  
  import { ListComponent } from './list.component';
  import { defaultData, collectionName } from '../../config';
  import { initialState } from '../../reducers/reducer';
  
  
  const data = {
    sort: initialState.sort,
    list: [defaultData, defaultData],
  };
  
  describe(`${collectionName} ListComponent`, () =&gt; {
    let fixture;
    beforeEach(() =&gt; {
      TestBed.configureTestingModule({
        declarations: [
          ListComponent,
        ],
      }).compileComponents(); // compile template and css;
      fixture = TestBed.createComponent(ListComponent);
      fixture.componentInstance.data = data;
      fixture.detectChanges();
    });
  
    it('should render 2 items in list', () =&gt; {
      const el = fixture.debugElement.nativeElement;
      expect(el.querySelectorAll('.box').length).toBe(3);
    });
  });
  </code></pre>
  
  <p>I looked at several answers to similar questions but could not find a solution that worked for me.</p>