I get this error in my unit tests for a directive that uses the BsModalService. Here's the error being thrown in the unit test (using Jasmine):
StaticInjectorError(Platform: core)[BsModalService -> ComponentLoaderFactory]:
NullInjectorError: No provider for ComponentLoaderFactory!
Error: StaticInjectorError(DynamicTestModule)[BsModalService -> ComponentLoaderFactory]:
My testbed setup:
beforeEach(async(() => {
TestBed.configureTestingModule({
providers: [
BsModalService,
BsModalRef,
Title,
{ provide: SessionKeepAliveService, useClass: SessionKeepAliveStubService },
{ provide: ApplicationStateService, useClass: ApplicationStateStubService },
{ provide: DocumentService, useClass: MockDocumentService }
],
imports: []
});
}));
My unit test:
it('should set sessionTimeOutLength to the value from the KeepALiveService',
async(inject([ApplicationStateService, SessionKeepAliveService, BsModalService, Title, DocumentService],
(appStateService: ApplicationStateService, keepAliveService: SessionKeepAliveService, modalService: BsModalService, titleService: Title, documentService: DocumentService)
=> {
const directive = new SessionTimeoutDirective(appStateService, keepAliveService, modalService, titleService, documentService);
keepAliveService.keepSessionAlive().subscribe(t => {
expect(directive.sessionTimeoutLength).toEqual(t.sessionTimeout);
});
})));
ngx-bootstrap: 2.0.5
Angular: 5.2.6
Bootstrap: 3.x
Angular Cli: v1.6.8
webpack: v3.10,
jasmine: v2.8
Found that the testbed setup needed needed an import for ModalModule.forRoot()
beforeEach(async(() => {
TestBed.configureTestingModule({
providers: [
BsModalService,
BsModalRef,
Title,
{ provide: SessionKeepAliveService, useClass: SessionKeepAliveStubService },
{ provide: ApplicationStateService, useClass: ApplicationStateStubService },
{ provide: DocumentService, useClass: MockDocumentService }
],
imports: [ModalModule.forRoot()]
});
}));
Most helpful comment
Found that the testbed setup needed needed an import for ModalModule.forRoot()