1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

TranslatePipe in test with Jest

Discussão em 'Angular' iniciado por Valentina Maronese, Novembro 7, 2024 às 09:22.

  1. I'm facing this error when I try to run test in an Angular project:

    NavigationMainComponent › should create
    TypeError: Cannot read properties of undefined (reading 'subscribe')
    at _TranslatePipe.transform (node_modules/@ngx-translate/core/dist/fesm2022/ngx-translate-core.mjs:928:75)


    I tried to mock the TranslatePipe but nothing changes. I have mocked the TranslateService in this way:

    { provide: TranslateService, useValue: mock.translateServiceMock },

    export const translateServiceMock = {
    addLangs: jest.fn(),
    setDefaultLang: jest.fn(),
    use: jest.fn().mockReturnValue(of('da')),
    getLangs: jest.fn().mockReturnValue(['da', 'en']),
    get: jest.fn().mockReturnValue(of('translated text')),
    instant: jest.fn((key: string) => key),
    onLangChange: of({ lang: 'en' }),
    };


    Also, I added TranslateModule.forRoot() to the imports. I don't know what is missing to make the test run properly.

    Continue reading...

Compartilhe esta Página