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

186
Visualizações
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 à 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