I am trying to test one of my components using Jasmine and Karma and it fails with the following error = "Error in app/components/login.js class LoginComponent_Host - inline template:0:0 caused by: Bootstrap at least one component before injecting Router".
The same kind of test works without any issues for our root component. Here is the test code -
import { LoginComponent } from './login';
import { TestBed, async } from '@angular/core/testing';
import { AppModule } from "../app.module";
import { APP_BASE_HREF } from "@angular/common"
describe('LoginComponent', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [ AppModule ],
providers: [ { provide: APP_BASE_HREF, useValue : '/' } ]
});
});
it('should instantiate component', async(() => {
TestBed.compileComponents().then(() => {
let fixture = TestBed.createComponent(LoginComponent);
fixture.detectChanges();
expect(fixture.componentInstance instanceof LoginComponent).toBe(true, 'should create LoginComponent');
});
}));
});
LoginComponent is part of AppModule and here is how AppModule is setup:
@NgModule({
imports: [
BrowserModule,
FormsModule,
HttpModule,
routing
],
declarations: [
AppComponent,
LoginComponent,
SponsorsComponent
],
providers: [
AuthenticationService,
UserService
],
bootstrap: [ AppComponent ]
})
export class AppModule { }
The same test works without any issues for AppComponent which is the root component of the AppModule. Wondering if there is any testbed setup that needs to be done to bootstrap AppComponent ? Please let me know if there are any suggestions that I could try. Thanks in advance.