core icon indicating copy to clipboard operation
core copied to clipboard

TypeError: this.currentLoader.getTranslation is not a function

Open yesssirskii opened this issue 1 year ago • 3 comments

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 avatar Jan 17 '23 12:01 yesssirskii

@yesssirskii you can use TranslateFakeLoader instead of TranslateLoader it will fix your problem

bms1995 avatar Mar 21 '23 01:03 bms1995

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!"

nbwhub avatar Oct 19 '23 19:10 nbwhub

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

wavua avatar Mar 15 '24 08:03 wavua