Jasmine clock

For cases, when we need to use the setTimeout() or setInterval() functions of JavaScript in our tests: Jasmine provides a clock that can make use of these functions available.

jasmine.clock().install() installs a clock for our specs and jasmine.clock().uninstall() restores the original JavaScript timer functions. Jasmine clock helps us handle time-dependent code using these functions. Let's see the following examples to understand how these work.

Suppose we want to check if Alice, an employee, was available after an hour, we create a spy for the checkAvailabity() function for an employee object:

var employee; beforeEach(function() { employee = new Employee("Alice", 5, "Testing"); employee.checkAvailability = jasmine.createSpy("checkAvailability"); ...

Get Test-Driven JavaScript Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.