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

179
Views
Jest/fetch-mock ignorando setTimeout dentro de Promise

Creé una función que repetirá una solicitud HTTP 3 veces cada 1500 ms si el estado es 5xx.

 const fetchRetry = (url: string, options = {}, retries = 3, timeout = 1500) => { return new Promise((resolve) => { fetch(url, options).then((res) => { if (res.ok) return resolve(res); if (retries > 0 && res.status >= 500 && res.status < 600) { setTimeout(() => { resolve(fetchRetry(url, options, retries - 1, timeout)); }, timeout); } else { return resolve(res); } }); }); }; export default fetchRetry;

Funciona bien en el navegador, pero está provocando errores en muchas pruebas.

Este es un ejemplo de una prueba que tengo:

 fetchMock.postOnce("/my-api", { status: 503, }); const expectedActions = [ { itemRef: "sample", }, ]; return store .dispatch(myAction.findRef(itemRef)) .then(() => { expect(store.getActions()).toEqual(expectedActions); });

Básicamente, estoy probando mi código usando jest y fetch-mock , como puede ver, me estoy burlando de la solicitud de la API y estoy esperando a que se myAction.findRef(itemRef) (Promise).

Siempre recibo: Timeout - Async callback was not invoked within the 5000 ms timeout specified by jest.setTimeout.Timeout - Async callback was not invoked within the 5000 ms timeout specified by jest.setTimeout.Error: .

Si setTimeout , funcionará. Lo cual es extraño.

También traté de incrementar el jest.setTimeout.Timeout pero sin suerte.

¿Algunas ideas?

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!