Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

253
Visualizações
JS/Angular: Pipes testing problem after upgrading to the latest version of Jest (27.4.7)

After upgrading the version of Jest to the latest one my unit tests for pipe are failing. The initial error I was getting was:

jest Cannot set property of [object Object] which has only a getter

This error was not present in the earlier version (24).

I found a similar problem but unfortunately the applied solution did not help in my case.

This is my pipe:

@Pipe({
  name: 'standPermissionIds',
})
export class StandPermissionIdsPipe implements PipeTransform {
  transform(value: Stands): StandIdentifiers | undefined {
    if (!value) {
      return;
    }
    return extractStandIdentifiers(value);
  }
}

and tests for that (before applying the solution to get rid off 'getter' error):

import { StandPermissionIdsPipe } from '@sam-hmi/shared/pipes/stand-permission-ids.pipe';
import { extractStandIdentifiers } from '@sam-hmi/utils';

describe('StandPermissionIdsPipe', () => {
  let pipe;

  beforeEach(() => {
    pipe = new StandPermissionIdsPipe();
    (extractStandIdentifiers as jest.Mock) = jest.fn();
  });

  it('should call extractStandIdentifiers and return the value', () => {
    pipe.transform('test');
    expect(extractStandIdentifiers).toBeCalledWith('test');
  });
});

and after applying it:

import { StandPermissionIdsPipe } from '@sam-hmi/shared/pipes/stand-permission-ids.pipe';

describe('StandPermissionIdsPipe', () => {
  let pipe;
  let extractStandIdentifiers;

  beforeEach(() => {
    pipe = new StandPermissionIdsPipe();
    extractStandIdentifiers = jest.mock('@sam-hmi/utils', () => ({
      ...jest.requireActual('@sam-hmi/utils'),
    }));
  });

  it('should call extractStandIdentifiers and return the value', () => {
    pipe.transform('test');
    expect(extractStandIdentifiers).toHaveBeenCalledWith('test');
  });
});

In that case the error message is about something else but probably because I screwed applying the solution: enter image description here

And this is how the extractStandIdentifiers looks like:

export const extractStandIdentifiers = (stand: Stands): StandIdentifiers => {
  const { standId, terminalFk, apronFk, stationFk } = stand;
  return {
    standId,
    terminalId: terminalFk ? terminalFk.terminalId : undefined,
    apronId: apronFk ? apronFk.apronId : undefined,
    stationId: stationFk ? stationFk.stationId : undefined,
  };
};

Can someone please explain to me how to solve this and what has changed and why I started getting these errors in the newer version of Jest?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda