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

189
Visualizações
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 à 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