Upon running ng test
, I get an error stating:
Error: Illegal state: Could not load the summary for directive AppComponent.
I'm not sure why I'm getting this error, as I'm referencing and declaring AppComponent.
This is my app.component.spec.ts
import { ComponentFixture, TestBed } from "@angular/core/testing";
import { NO_ERRORS_SCHEMA } from "@angular/core";
import { Router } from "@angular/router";
import { ProjectService } from "../../shared/service/project/project.service";
import { AppComponent } from "./app.component";
describe("AppComponent", () => {
let comp: AppComponent;
let fixture: ComponentFixture<AppComponent>;
beforeEach(() => {
const routerStub = {
navigate: () => ({})
};
const projectServiceStub = {
GetActiveProject: () => ({
name: {}
})
};
TestBed.configureTestingModule({
declarations: [ AppComponent ],
schemas: [ NO_ERRORS_SCHEMA ],
providers: [
{ provide: Router, useValue: routerStub },
{ provide: ProjectService, useValue: projectServiceStub }
]
});
fixture = TestBed.createComponent(AppComponent);
comp = fixture.componentInstance;
});
it("can load instance", () => {
expect(comp).toBeTruthy();
});
describe("ngOnInit", () => {
it("makes expected calls", () => {
const routerStub: Router = fixture.debugElement.injector.get(Router);
const projectServiceStub: ProjectService = fixture.debugElement.injector.get(ProjectService);
spyOn(routerStub, "navigate");
spyOn(projectServiceStub, "GetActiveProject");
comp.ngOnInit();
expect(routerStub.navigate).toHaveBeenCalled();
expect(projectServiceStub.GetActiveProject).toHaveBeenCalled();
});
});
});
Why is it throwing this error and how can I fix this error?
EDIT: I'm using the Angular CLI's default tsconfig and tsconfig.spec files. I've upgraded to Angular 6 in the meantime, I get the sam error. Even creating a new project with clean config files and replacing the src folder did not resolve the error.