поэтому я пытаюсь создать простое обещание тайм-аута
const delay = (time, value) => {
return Promise.resolve(); // THIS WORKS
// NEED TO, but wont work
return new Promise(function(resolve) {
setTimeout(() => resolve(value), time);
});
};
const request = (count) => {
if (count === 15) return;
return makeRequest().then(
res => Promise.resolve() // if it works it works.
).catch(
err => delay(1000).then(() => request(count - 1));
)
}
describe("on fail", () => {
beforeEach(() => jest.useFakeTimers());
it("should retry 15 times", async () => {
request();
jest.runTimersToTime(15001); // alias `advanceTimersByTime`
await expect(request.mock.calls.length).toBe(15); // what am i missing? or rather, what's jest missing?
});
});