None of my components were passing unit tests, so I made a new one in the project to try and diagnose.
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-thing',
templateUrl: './thing.component.html',
styleUrls: ['./thing.component.scss']
})
export class ThingComponent implements OnInit {
constructor() { }
ngOnInit() {
}
}
And a thing.component.spec.ts
file as follows
describe('ThingComponent', () => {
let component: ThingComponent;
let fixture: ComponentFixture<ThingComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ ThingComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ThingComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
The test fails with
Error: Illegal state: Could not load the summary for directive ThingComponent.
I have turned off all other tests with xit
, so this is the only one running.
I have tried to move in everything (providers, imports, etc) from my app.module.ts
into the file, which still provides the same result.
When I remove the TestBed configuration, and just have a
const comp = new ThingComponent();
expect(comp).toBeTruthy();
this passes. However, that's not a long term solution for actual components.
Versions of things:
"@angular/cli": "^1.7.2",
"@angular/compiler-cli": "^5.2.0",
"@angular/language-service": "^5.2.0",
"@types/jasmine": "~2.5.53",
"@types/jasminewd2": "~2.0.2
"jasmine-core": "~2.6.2",
"jasmine-spec-reporter": "~4.1.0",
"karma": "~1.7.0",
"karma-chrome-launcher": "~2.1.1",
"karma-cli": "~1.0.1",
"karma-jasmine": "^1.1.1",
"karma-jasmine-html-reporter": "^0.2.2",
...
"@angular/animations": "^5.2.0",
"@angular/common": "^5.2.0",
"@angular/compiler": "^5.2.0",
"@angular/core": "^5.2.0",
"@angular/forms": "^5.2.0",
"@angular/http": "^5.2.0",
"@angular/platform-browser": "^5.2.0",
"@angular/platform-browser-dynamic": "^5.2.0",
Any help at all would be appreciated, thanks
Update
I even changed the test to expect(true).toBeTruthy()
and it still gets the same error. I've changed nothing else in the code that was provided by ng g component
.
Additionally, I made a new angular project in a separate directory, and the tests pass on this new blank project.