Angular 5 using material, jasmine karma test fail with mat-icon

Issue

I’m trying to run jasmine karma with

ng test

Surprise with all the issues with Angular Materials. I see example of OLDER version of material many months ago when it was called md-icon instead of mat-icon etc…

Thus this doesn’t fix the errors thrown

MaterialModule.forRoot()

Error

mat-icon is not a known element angular material

Solution

I was experiencing the same issues testing Material components.

Thanks to k.vincent for providing the correct answer for me in the comments.

For components using Material, ensure your *.spec file looks similar to this:

import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';

...

beforeEach(async(() => {
    TestBed.configureTestingModule({
        declarations: [ MyComponent ],
        schemas: [ CUSTOM_ELEMENTS_SCHEMA ]
    })
    .compileComponents();
}));

Answered By – mkubal

Answer Checked By – Mildred Charles (AngularFixing Admin)

Leave a Reply

Your email address will not be published.