Ngx-bootstrap: Testing: StaticInjectorError BsDropdownDirective -> ComponentLoaderFactory WITH forRoot()

Created on 25 Jun 2018  路  5Comments  路  Source: valor-software/ngx-bootstrap

Bug description or feature request:

I updated my project to latest Angular version and also updated the dependencies. The application is running fine now but when I run the tests (ng test) I'm experiencing the following error in my AppComponent (app.component.spec.ts):

Error: StaticInjectorError(DynamicTestModule)[BsDropdownDirective -> ComponentLoaderFactory]: StaticInjectorError(Platform: core)[BsDropdownDirective -> ComponentLoaderFactory]: NullInjectorError: No provider for ComponentLoaderFactory!

app.component.spec.ts:

declarations: [
        AppComponent,
        ForbiddenComponent
      ],
      imports: [
        HttpClientTestingModule,
        APP_IMPORTS
      ]

app.imports.ts:

export const APP_IMPORTS = [
  BrowserModule,
  FormsModule,
  HttpClientModule,
  RouterModule.forRoot(ROUTE_CONFIG, {enableTracing: false}),
  TranslateModule.forRoot({
    loader: {
      provide: TranslateLoader,
      useFactory: (createTranslateLoader),
      deps: [HttpClient]
    }
  }),
  StoreModule.forRoot(reducers),
  EffectsModule.forRoot([]),
  STORE_DEV_TOOLS_IMPORTS,
  ToastrModule.forRoot({
    maxOpened: 3,
    preventDuplicates: true,
    timeOut: 7000,
    progressBar: true,
    positionClass: "toast-bottom-left",
  }),
  BsDropdownModule.forRoot(),
  DatepickerModule.forRoot(),
  TooltipModule.forRoot(),
...
];

also adding BsDropdownModule.forRoot(), directly to app.component.spec.ts imports doesn't help. Any idea?

Plunker/StackBlitz that reproduces the issue:

None

Versions of ngx-bootstrap, Angular, and Bootstrap:

ngx-bootstrap: 3.0.1

Angular: 6.0.6

Bootstrap: bootstrap-sass 3.3.7

Build system: Angular CLI, System.js, webpack, starter seed:

Angular CLI 6.0.8

Most helpful comment

I had the issue and it was dropdown directive missing from the upper div

All 5 comments

I have this error too.
Does anyone knows any fix?

Only happens in app.component.spec.ts! Other Tests that are using ngx-bootstrap as well work fine

@werthdavid
Please try to provide _BsDropdownModule.forRoot()_ into imports.

Still facing same issue... not working fine

Error: Uncaught (in promise): NullInjectorError: StaticInjectorError(AppModule)[BsDropdownDirective -> ComponentLoaderFactory]:
StaticInjectorError(Platform: core)[BsDropdownDirective -> ComponentLoaderFactory]:
NullInjectorError: No provider for ComponentLoaderFactory!
NullInjectorError: StaticInjectorError(AppModule)[BsDropdownDirective -> ComponentLoaderFactory]:
StaticInjectorError(Platform: core)[BsDropdownDirective -> ComponentLoaderFactory]:

I had the issue and it was dropdown directive missing from the upper div

Was this page helpful?
0 / 5 - 0 ratings