Book Image

Jasmine Cookbook

By : Munish Kumar
Book Image

Jasmine Cookbook

By: Munish Kumar

Overview of this book

Table of Contents (16 chapters)
Jasmine Cookbook
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

Writing Jasmine tests to mock the JavaScript timeout functions


With JavaScript, we can create a time-dependent program/code and execute it at a specified time or time intervals using the setTimeout() and setInterval() methods. In Jasmine, we can also handle time-dependent code (or time events) using Jasmine Clock. This can be installed with a call to jasmine.clock().install() in a spec or suite that needs to manipulate time. In this recipe, you will learn how to mock the JavaScript timeout functions using Jasmine Clock.

To understand this recipe, let's assume that you are developing a JavaScript application and you have to implement test code to handle JavaScript timeout functions (that are, setTimeout() and setInterval()).

"As a JavaScript developer, I want to develop Jasmine tests for JavaScript timeout functions using Jasmine Clock so that I can implement a test condition successfully."

Let's consider a scenario in the current context, that is, Jasmine tests should be created for JavaScript...