O'Reilly logo

Jasmine JavaScript Testing - Second Edition by Paulo Ragonha

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

Acceptance criterion

To demonstrate Jasmine support of asynchronous testing, we are going to implement the following acceptance criterion: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required