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

242
Views
Cómo usar Jest .mockImplementation tanto para lanzar y error como para devolver el estado

Estoy tratando de probar el bloque catch de este try/catch .

 try { const response = await request.get({ // ... required params here }); return response.data; } catch (error) { myFunction({ statusCode: error.response.status, }); throw error; }

Mi objetivo es probar la llamada de myFunction dentro de catch . Quiero confirmar que la función fue llamada con los parámetros correctos de { statusCode: 400 } por ejemplo.

También quiero probar que se arrojó un error.

Escribí una mockImplementation de request.get en un intento de obtener esta respuesta de error, pero no parece llamar a mi bloque catch .

 it("should throw an error and call myFunction with the status code", async () => { await request.get.mockImplementation(() => { throw new Error(); // how do I add return of statusCode here? }); expect(addToNewRelic).toHaveBeenCalledWith( expect.objectContaining({ productAPIRequestStatusCode: 404, }) ); });
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!