Danielduel
Danielduel2w ago

Skipping time in tests; time delay setTimeout setInterval

(the title is just so people can get to this one easier by using search) I have a deadline/delay based (@std/async) functionality and in tests I want to skip time (so I don't have to pass lower values for timeouts). I want something like jest's advanceTimersByTime (very bright page warning, usage is at the bottom) https://jestjs.io/docs/timer-mocks (jest uses sinon's fake timers, sinon uses sinon/fake-timers (install, then createClock, it's basically a big orchiestrated mock on time-based apis)) No idea if sinon works with deno (and if it is the deno's way), I would prefer something jsr/deno for this, any recommendation?
3 Replies
robbie
robbie2w ago
Deno’s FakeTime is what you’re looking for. I’m using it right now, and it’s great. https://jsr.io/@std/testing/doc/time
JSR
time - @std/testing - JSR
@std/testing on JSR: Tools for testing Deno code like snapshot testing, bdd testing, and time mocking
robbie
robbie2w ago
Also make sure to use Deno's built in intervals, instead of the node equivalents
Danielduel
DanielduelOP2w ago
Thank you! ❤️ (I have to check it still, but it sounds exactly what I am looking for)