"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.
Error: No provider for TranslateStore
Asked Answered
that is not very much information you're providing to us, it would be easier to get some code of the tests that crash, so we can help you better –
Womanize
Try this:
import {TranslateFakeLoader,TranslateLoader,TranslateModule,TranslateService } from '@ngx-translate/core';
TestBed.configureTestingModule({
imports: [
...
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useClass: TranslateFakeLoader
}
})
],
...
providers: [
TranslateService
]
Please check this out: npmjs.com/package/@ngx-translate/core –
Night
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
After that my translations do not work –
Semiporcelain
This seemed to be the solution for me (and my translations still work) –
Gandhiism
If none of the previous solutions worked for you.
Try this solution:
Please remove the modules imported in the imports: [] array and Use the components of the module directly in the declarations: [] array by using MockComponents(). Except the modules which contains entryComponents.
Example:
import { MockComponents } from 'ng-mocks';
TestBed.configureTestingModule({
imports: [
...,
TranslateModule.forRoot()
],
declarations: [
myComponent,
MockComponents(component1, component2)
],
...
providers: [
TranslateService
]
© 2022 - 2024 — McMap. All rights reserved.