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

203
Visualizações
jest.spyOn no funciona cuando se llama desde una llamada de efecto secundario

Tengo el siguiente escenario:

 const doSomething = () => { const test = 1; doAnotherThing(); return test + 1; }; const doAnotherThing = () => {}; module.exports = { doSomething, doAnotherThing };

Y aquí está mi prueba:

 const MyModule = require('./myModule'); describe('MyModule', () => { it('Should be able to spy another call', () => { const spy = jest.spyOn(MyModule, 'doAnotherThing'); MyModule.doSomething(); expect(spy).toHaveBeenCalledTimes(1); }); });

Pregunta, ¿hay alguna manera de que la llamada doAnotherThing() dentro de doSomething() sea espiada por broma de alguna manera, sin usar soluciones como rewire?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Encontré la solución aquí: https://medium.com/welldone-software/jest-how-to-mock-a-function-call-inside-a-module-21c05c57a39f

Redefinido mi módulo a esto y ahora está funcionando

 const doSomething = () => { const test = 1; MyModule.doAnotherThing(); return test + 1; }; const doAnotherThing = () => {}; const MyModule = { doSomething: doSomething, doAnotherThing: doAnotherThing }; export default MyModule;
about 4 years ago · Juan Pablo Isaza Relatório
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