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

188
Views
Jest error on TS: second test can't instance the class

Setup

  • Node: 14.x
  • Jest: ^26.6.3
  • ts-jest: ^26.4.4
  • typescript: ^4.0.5
  • some whatever etc...

Scenario
There's a file with a bunch of controllers and each one instances a class from other file, every time that it receives a response from an API.
Everything is in the same folder, even the test, it's a bad architecture, not the point here.
The objective of the tests is to test only the controllers, not the response class, which is called, ServiceResponseClass.

Running
The first test runs successfully, without any error. But it doesn't even stops on the breakpoint inside the constructor, which is very odd, maybe not much relevant.
From the second test and beyond the tests fails and the received values are:

[TypeError: ServiceResponse_d_1.ServiceResponseClass is not a constructor]


Attempts
I tried to use jest.mock pointing to jest.requireActual and it didn't worked, even inside beforeEach, as described here.
It isn't a import problem, as described here.
I've tried to mock the class and its methods as described here and here, but I've got stuck mocking the returns on each test.

Reviewing
I want to test only the controllers, without needing to mock the class instances inside of it. Or, if it's the only option, how should I do it? Solutions, readings suggestions, links, whatever you give me is something welcome.

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!