Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

191
Vistas
Sinon fakeserver doesn't respond when API's are invoked from a callback of setTimeout

Like the title of this question says sinon fake server is not responding to the API/ajax calls made from a callback of setTimeOut.

Status.js

_checkStatus() {
    if (...) {
      ....
      }
    } else if (...) {
      ....
    } else {
      setTimeout(async () => {
        this.status = await services.getStatus();
        this._checkStatus();
      },100);
    }
  }

Status.test.js

    const API_STATUS = /\/status/;
    const cType = { 'Content-Type': 'application/json' };
    const mocks = {};
    mocks.get = { code: 'ready' };
    const server = fakeServer.create();
    server.respondImmediately = true;
    server.respondWith(API_STATUS, [200, cType, JSON.stringify(mocks.get)]);
    el._checkStatus();

    setTimeout(function(done){
      expect(el.status).to.equal('ready');
      done();
    }
      ,500);
  });

When we execute this test it invokes the mocks that are defined in the repo folder but not picking up the fake server mock defined above. However if I move the getStatus() call outside the timeout then it works with fake server. Just an FYI that getStatus() invokes the status API call.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda