How to mock Transloco service in Jest unit testing? Angular

Discussão em 'Angular' iniciado por Maksat Madeniyetov, Novembro 22, 2024.

  1. let translocoServiceMock: any; // jest.Mocked<TranslocoService>

    beforeEach((async () => {
    translocoServiceMock = {
    setActiveLang: jest.fn(),
    };

    await TestBed.configureTestingModule({
    providers: [
    { provide: TranslocoService, useValue: translocoServiceMock },
    ],
    imports: [getTranslocoModule()],
    }).compileComponents();
    }));


    How to mock TranslocoService?

    1. Is it possible to use this type jest.Mocked<TranslocoService> instead of any? (here let translocoServiceMock: any; // jest.Mocked<TranslocoService>)
    2. How can I mock TranslocoService, in this code above it gives an error that I need to define all methods but I only need one method setActiveLang: jest.fn(),

    Continue reading...

Compartilhe esta Página