Illegal state: Could not load the summary for directive (component): Angular 4 unit testing

lewtur Source

I generated an Angular App with the Angular CLI, and using ng test to test the components with Karma.

I'm using Angular v5.2.0.

When running the tests, I get the error: Error: Illegal state: Could not load the summary for directive DashboardComponent.

I've read other posts on here with a similar issue, which have been solved by adding the component under test, as well as any used components into the declarations property of the TestBed.

I did this, and still got the same error. I've then imported and declared literally every component in my app, and still get the same error.

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

  beforeEach(() => {

    TestBed.configureTestingModule({
      imports: [
        FormsModule,
        BrowserAnimationsModule,
        NgbModule.forRoot(),
        BrowserModule,
        FormsModule,
        NgbModule.forRoot(),
        NgwWowModule.forRoot(),
        HttpModule,
        BrowserAnimationsModule,
        CookieModule.forRoot(),
        AgmCoreModule.forRoot({...}),
        LoadingModule.forRoot({...}),
        DragScrollModule,
        ClickOutsideModule
      ],
      declarations: [
        AppComponent,
        DashboardComponent,
        GigsOnDateComponent,
        SpotifyTrendingComponent,
        NewAlbumsComponent,
        FirstTimeSetupComponent,
        SafeHtmlPipe,
        SafeUrlPipe,
        FriendlyDatePipe,
        SettingsComponent
      ],
      providers: [
        MusicService,
        MainService,
        NgbModal,
        CookieService,
        NgbActiveModal,
        NgwWowService
      ]
    });

    fixture = TestBed.createComponent(DashboardComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
  });

  it('should create', () => {
    expect(component).toBeTruthy();
  });

Any help is appreciated.

Thanks

angularunit-testingkarma-runnerangular5

Answers

comments powered by Disqus