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: ...

Get Jasmine JavaScript Testing - Second Edition 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.