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

359
Views
¿Cómo evitar que Jest vea que se llama a una función o que implementa la función de manera diferente?

Tengo un script con una función que se llama al final. Quiero evitar que doSomething() arroje un error en las pruebas de broma.

calculadora.js

 const add = (a, b) => { return a + b; } function doSomething(){ throw Error('dang I messed you up') } doSomething(); // 👈 this gets call in Jest test everytime module.exports = { add, somethingElse }

En el archivo de prueba, quiero evitar que se llame a doSomething() :

 const Calc = require('../calculator.js'); const { add, doSomething } = Calc; // prevent doSomething() from being called 👈 doSomething.mockImplementation(() => console.log('so much nope')); // or jest.spyOn(Calc, 'doSomething').mockImplementation(() => console.log('so much nope')); test('Adding two numbers', async () => { expect(add(5, 5)).toStrictEqual(10) })

Jest no está cambiando la implementación, sino que aún muestra el error.

broma al ver el error de doSomething

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!