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

110
Views
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
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!