Romanchuk / angular-i18next

angular v10+ integration with i18next v19.4+
MIT License
130 stars 33 forks source link

Component testing #64

Closed duPleX93 closed 3 years ago

duPleX93 commented 3 years ago

Hello Romanchuk! Unfortunately, your example does not help me :/ Can you give some advice pls, what did I do wrong?

When I run my test file, I get 2 errors: 1.) NullInjectorError: No provider for InjectionToken I18NEXT_SERVICE! 2.) Error: The pipe 'i18next' could not be found!

And my Test file:

`export function appInit(i18next: ITranslationService) { return () => { const promise: Promise = i18next .init({ debug: true, lng: 'cimode' }); return promise; }; }

export function localeIdFactory(i18next: ITranslationService) { return i18next.language; }

export const I18N_PROVIDERS = [ { provide: APP_INITIALIZER, useFactory: appInit, deps: [I18NEXT_SERVICE], multi: true }, { provide: LOCALE_ID, deps: [I18NEXT_SERVICE], useFactory: localeIdFactory }, ];

describe('NavComponent', () => { let component: NavComponent; let fixture: ComponentFixture;

beforeEach(async () => { await TestBed.configureTestingModule({ imports: [ BrowserModule, UiElementsModule, RouterTestingModule, HttpClientModule, BrowserAnimationsModule, MatExpansionModule, I18NextModule.forRoot() ], declarations: [ NavComponent ], providers: [ { provide: 'environment', useValue: environment }, { provide: UserManagerService, useClass: MockUserManagerService }, I18N_PROVIDERS ], }) .compileComponents(); });`

duPleX93 commented 3 years ago

I forgot to add I18NextModule.forRoot() to my App component. So it's working!