core
core copied to clipboard
TypeError: this.currentLoader.getTranslation is not a function
I am trying to test a component in Angular but when I try to test it I get the following
TypeError: this.currentLoader.getTranslation is not a function
error.
Here is my code, if anyone can help I would highly appreciate it!!
import { HttpClient, HttpHandler } from '@angular/common/http';
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { RouterTestingModule } from '@angular/router/testing';
import { DEFAULT_LANGUAGE, MissingTranslationHandler, TranslateCompiler, TranslateLoader, TranslateModule, TranslateParser, TranslateService, TranslateStore, USE_DEFAULT_LANG, USE_EXTEND, USE_STORE } from '@ngx-translate/core';
import { TranslateHttpLoader } from '@ngx-translate/http-loader';
import { DialogService } from 'primeng/dynamicdialog';
import { PartyListComponent } from './party-list.component';
describe('PartyListComponent', () => {
let component: PartyListComponent;
let fixture: ComponentFixture<PartyListComponent>;
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [PartyListComponent],
imports: [RouterTestingModule, TranslateModule],
providers: [
HttpClient,
HttpHandler,
DialogService,
TranslateService,
TranslateStore,
TranslateLoader,
TranslateCompiler,
TranslateParser,
MissingTranslationHandler,
{ provide: USE_DEFAULT_LANG, useValue: {} },
{ provide: USE_STORE, useValue: {} },
{ provide: USE_EXTEND, useValue: {} },
{ provide: DEFAULT_LANGUAGE, useValue: {} },
]
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(PartyListComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
@yesssirskii you can use TranslateFakeLoader instead of TranslateLoader it will fix your problem
I'm having this same error. When I add TranslateFakeloader instead, this error shows: TypeError: this.parsser.getValue is not a function....and I had to add .forRoot() to the TranslateModule in imports or I get the error "No provider for TranslateLoader!"
This
I'm having this same error. When I add TranslateFakeloader instead, this error shows: TypeError: this.parsser.getValue is not a function....and I had to add .forRoot() to the TranslateModule in imports or I get the error "No provider for TranslateLoader!"
This solution also worked for me