Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

246
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda