Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

252
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!