How to make material components work with Karma in unit testing Angular
Current technique calls for individual imports of Angular Material modules, as MaterialModule
is deprecated and was removed in 2.0.0-beta.11:
import {
MatButtonModule,
MatIconModule
} from '@angular/material';
Then add the same list as imports in the TestBed config:
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ ... ],
imports: [
MatButtonModule,
MatIconModule,
...
],
providers: [ ... ]
})
.compileComponents();
}));
All the providers are provided by calling forRoot()
on the module
imports: [ MaterialModule.forRoot() ]
For versions 2.0.0-beta.4
and later (since the forRoot
method has been removed):
imports: [ MaterialModule ]
For versions 2.0.0-beta.11
and later, since MaterialModule
has been removed, you have to import the modules you require for your test cases yourself:
imports: [ MatButtonModule, MatDialogModule ]