I'm testing my DashboardComponent, this is my beforeEach block:
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
FormsModule,
routing
],
declarations: [
DashboardComponent,
Ellipsis,
FavouritesComponent,
FormatDuration,
LoginComponent,
SearchComponent
],
});
this.fixture = TestBed.createComponent(DashboardComponent);
});
It already has a few imports that have nothing to do with the dashboard (like LoginComponent). But it keeps asking for more imports:
Error: Component **** is not part of any NgModule or the module has not been imported into your module.
Everything in app.module.ts is present so that's not the problem.
What causes this kind of behaviour and how can I resolve it?
Add AppModule and RouterTestingModule to imports of the object you pass to TestBed.configureTestingModule().
Not sure if you still need to add {provide: APP_BASE_HREF, useValue: '/'} when RouterTestingModule is imported.
See also this PR for the upcoming testing docs https://github.com/angular/angular.io/pull/2198/files
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With