AnaCS
AnaCS

Reputation: 1011

ionic errors with unit testing ionic 4 app

I am trying to write the most basic of unit tests like this one here

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

and I always get errors like

Failed: Template parse errors: Can't bind to 'routerLink' since it isn't a known property of 'ion-item'. 1. If 'ion-item' is an Angular component and it has 'routerLink' input, then verify that it is part of this module. 2. If 'ion-item' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. 3. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component. ("ggle auto-hide="false" *ngFor="let p of appPages"> ][routerLink]="[p.url]"> "): ng:///DynamicTestModule/AppComponent.html@6:49 The pipe 'translate' could not be found (" [ERROR ->] {{ p.title | translate }} "

it's like ng test unit tests doesn't accept any ionic elements in html? I am importing indeed the forms module and the ionic module in my spec file.

Upvotes: 1

Views: 533

Answers (1)

Julien METRAL
Julien METRAL

Reputation: 1974

Because of testing, you have to provide the NO_ERRORS_SCHEMA property in your TestBed to prevent schema errors, you don't need to provide IonicModule :

TestBed.configureTestingModule({
  declarations: [ AppComponent ],
  schemas: [ NO_ERRORS_SCHEMA ]
})
.compileComponents();

it looks like you have to provide the TranslateModule.

Upvotes: 2

Related Questions