When running my unit tests, from time to time, even if they pass, at the end of all the tests running, I will get the following error.
On my Jenkins CI build running
My specific issue with this error was caused by not mocking sub-components of the component I was testing. In this case I had a homepage component with two sub components, which required declarations for the sub components, which I failed to mock.
As a result the sub components had real dependencies which would intermittently cause the tests to fail in this non-obvious manner (it looks like different tests are randomly failing, but it is not the case).
Mocking as follows works pretty well in this case:
@Component({
selector: 'app-exercise',
template: 'Mock Exercise Component
'
})
class MockExerciseComponent {
}
@Component({
selector: 'app-user',
template: 'Mock User Component
'
})
class MockUserComponent {
}
describe('HomepageComponent', () => {
let component: HomepageComponent;
let fixture: ComponentFixture;
beforeEach(async(() => {
TestBed.configureTestingModule({
// note you need to mock sub components!
declarations: [HomepageComponent, MockExerciseComponent, MockUserComponent],