Book Image

Jasmine JavaScript Testing Update

By : Paulo Vitor Zacharias Ragonha
Book Image

Jasmine JavaScript Testing Update

By: Paulo Vitor Zacharias Ragonha

Overview of this book

Table of Contents (15 chapters)

Chapter 4. Asynchronous Testing – AJAX

Inevitably, there comes a time in every JavaScript application when asynchronous code needs to be tested.

Asynchronous means that you cannot deal with it in a linear fashion—a function might return immediately after its execution, but the result will come later, usually through a callback.

This is a very common pattern while dealing with AJAX requests, for example, through jQuery:

$.ajax('http://localhost/data.json', {
  success: function (data) {
    // handle the result
  }
});

In this chapter, we are going to learn the different ways Jasmine allows us to write tests for asynchronous code.