Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: No provider for TranslateStore

"Error: No provider for TranslateStore!" while UI Unit testing translation service in Angular 4. After I run ng test command I get the test cases failed error along with the above error message.

like image 723
Neelesh Avatar asked Dec 06 '17 10:12

Neelesh


2 Answers

Try this:

import {TranslateFakeLoader,TranslateLoader,TranslateModule,TranslateService } from '@ngx-translate/core';

TestBed.configureTestingModule({
      imports: [
        ...
        TranslateModule.forRoot({
          loader: {
            provide: TranslateLoader,
            useClass: TranslateFakeLoader
          }
        })
      ],
      ...
      providers: [
        TranslateService
      ]
like image 141
bradd Avatar answered Oct 24 '22 15:10

bradd


Importing & adding TranslateStore to the providers in my lazy loaded module resolved issue for me.

import { TranslateModule,TranslateService,TranslateStore } from '@ngx-translate/core';

export function createTranslateLoader(http: HttpClient) {
  return new TranslateHttpLoader(http, './assets/i18n/', '.json');
}

    @NgModule({
      declarations: [...],
      imports: [
        TranslateModule.forChild(
            {
            loader: {
              provide: TranslateLoader,
              useFactory: (createTranslateLoader),
              deps: [HttpClient]
          }
        
              })],
              providers:[TranslateStore ]
    })

Check the issue link below for more information

https://github.com/ngx-translate/core/issues/883#issuecomment-502037966

like image 43
dc7 Avatar answered Oct 24 '22 16:10

dc7