Timer Mocks
The native timer functions (i.e., setTimeout()
, setInterval()
, clearTimeout()
, clearInterval()
) are less than ideal for a testing environment since they depend on real time to elapse. Jest can swap out timers with functions that allow you to control the passage of time. Great Scott!
備考
Also see Fake Timers API documentation.