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

111
Vistas
Sinon fakeTimer causing timeout?

I'm very new to mocha, sinon, chai, etc. and I'm trying to write a test that asserts a method is called x times after a 1 second interval.

At the moment, when I place:

clock = sinon.useFakeTimers();

in my before(async () =>{}) block, it causes a timeout of that test.

I haven't even implemented the assertion yet but here's my code so far.

  describe('and mutiple calls to Lokalise suceed after', () => {
    describe('being rate limited', () => {
      let clock;
      before(async () => {
        clock = sinon.useFakeTimers();
        let promises = [];

        for(let i = 0; i<10; i++){
          promises.push(when.the_handler_is_invoked_because.a_forwarded_task_closed_event_is_received(lokaliseProject, task))
        };
        await Promise.all(promises);
        clock.tick(1000);
      });

      after(() => {
        clock.restore();
        teardown.unmock_everything();
      });

      it('eventually succeeds in creating the pull request', () => {
        expect(lokaliseProject._requestsToDownloadFiles).to.have.lengthOf(10);
        expect(lokaliseProject._requestsToDownloadFiles[0].include_tags).deep.equal(['challenge-api']);
        // Eventual expect for a method to be called x times
      });
    });
  });

I've removed some of the code to anonymise it a bit, but yeah is there anything standing out that would cause the timeout?

Thank you!

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