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 specs for asynchronous operations using the done() function


To test JavaScript's asynchronous functions/calls is a challenge. However, Jasmine 2.x provides a good way to test functions that are called asynchronously. In this recipe, you will learn to develop Jasmine specs for asynchronous operations using the done() function.

To understand this recipe, let's assume that you are developing an application using JavaScript and you have to design specs for asynchronous operations.

"As a JavaScript developer, I want to create Jasmine specs for asynchronous operations so that I can implement a test condition successfully."

Let's consider the following scenario in the current context:

  • Scenario-1: Jasmine should support JavaScript asynchronous operations using the done() function

How to do it…

To design specs for asynchronous operations, you need to perform the following steps:

  1. Create the asynchronous_with_done_spec.js file under the /spec folder and code the following lines:

    describe(...