The easiest way to freeze or travel through time in a Jasmine spec is to use the built-in
jasmine.clock()
Show archive.org snapshot
.
jasmine.clock().install()
you can use it to control setTimeout
and setInterval
.jasmine.clock().mockDate()
you can mock new Date()
(which returns the current time in Javascript)While you can use SinonJS Fake timers Show archive.org snapshot , using the built-in Jasmine clock will save you an extra dependency.