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!