mardi 18 octobre 2016

Error while testing component with router-outlet

I have created angular 2 project with angular-cli. I created separate AppRoutingModule which exports RouterModule and is added to AppModule imports array.

I have also appComponent created by angular-cli.

app.component.html

<nav>
  <a *ngFor="let view of views" routerLink="" routerLinkActive="active"></a>
</nav>
<router-outlet></router-outlet>

app.component.spec.ts

import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { TestBed, async } from '@angular/core/testing';
import { AppComponent } from './app.component';


describe('App: AquaparkFrontend', () => {
  beforeEach(() => {
    TestBed.configureTestingModule({
      declarations: [
        AppComponent
      ],
      schemas: [ CUSTOM_ELEMENTS_SCHEMA ]
    });
  });

  it('should create the app', async(() => {
    let fixture = TestBed.createComponent(AppComponent);
    let app = fixture.debugElement.componentInstance;
    expect(app).toBeTruthy();
  }));

  it(`should have 3 views`, () => {
    let fixture = TestBed.createComponent(AppComponent);
    let app = fixture.debugElement.componentInstance;
    expect(app.views.length).toEqual(3);
  });
});

When I try to run tests with ng test I have error:

 Can't bind to 'routerLink' since it isn't a known property of 'a'. ("<nav>
      <a *ngFor="let view of views" [ERROR ->]routerLink="" routerLinkActive="active"></a>
    </nav>
    <router-outlet><"

Do I miss something to import in test?

Aucun commentaire:

Enregistrer un commentaire