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