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

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