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)

Jasmine Ajax


Jasmine Ajax is an official plugin developed to help out the testing of AJAX requests. It changes the browser's AJAX request infrastructure to a fake implementation.

This fake (or mocked) implementation, although simpler, still behaves like the real implementation to any code using its API.

Installing the plugin

Before we dig into the spec implementation, first we need to add the plugin to the project. Go to https://github.com/jasmine/jasmine-ajax/ and download the current release (which should be compatible with the Jasmine 2.x release). Place it inside the lib folder.

It is also needed to be added to the SpecRunner.html file, so go ahead and add another script:

<script type="text/javascript" src="lib/mock-ajax.js"></script>

A fake XMLHttpRequest

Whenever you are using jQuery to make AJAX requests, under the hood it is actually using the XMLHttpRequest object to perform the request.

XMLHttpRequest is the standard JavaScript HTTP API. Even though its name suggests that it...