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

user9036522 picture user9036522 · Dec 22, 2017 · Viewed 11.8k times · Source

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

Answer

mkubal picture mkubal · Jan 4, 2018

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();
}));