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

184
Vistas
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
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