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.