Fixed Angular Material and Karma Error

If you are having trouble with Unknown ‘Angular Material Module’ element in your Angular Unit Test.
This could be the fix.

Add the Angular Material Module to the imports in beforeEach.

import { DebugElement } from '@angular/core';
import { By } from '@angular/platform-browser';

import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';

import { MatSidenavModule, MatCardModule } from '@angular/material';
import { DayscheduleComponent } from './../dayschedule/dayschedule.component';
import { WeekscheduleComponent  } from './../weekschedule/weekschedule.component';

import * as moment from 'moment';

describe('SchedulesComponent', () => {
  let component: SchedulesComponent;
  let fixture: ComponentFixture<SchedulesComponent>;

  let debugElement: DebugElement;
  let htmlElement: HTMLElement;

    async(() => {
        declarations: [SchedulesComponent, DayscheduleComponent, WeekscheduleComponent],
        imports: [ MatSidenavModule, MatCardModule, HttpModule, BrowserModule, BrowserAnimationsModule ]
It's only fair to share...Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn

Leave a Reply

Your email address will not be published. Required fields are marked *