Sinon.JS is a great library created by Christian Johansen, author of the great book, Test-Driven JavaScript Development, to make easy dealing with Stubs, Spies, and Mocks.

Although Jasmine already has support for Stubs and Spies, we are going to use a specific functionality of Sinon.JS to test AJAX requests, its FakeXMLHttpRequest and FakeServer functions.

The main difference between a Stub and a Fake, as you will see with the FakeXMLHttpRequest object, is that a Fake is like a simpler but still complete implementation of a real component, and it is usually set at a system level.

Installing Sinon.JS

Before we dig into the spec implementation, first we need to add Sinon.JS to the project. Go to and download the current ...

Get Jasmine JavaScript Testing now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.