O'Reilly logo

Jasmine JavaScript Testing 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

Sinon.JS

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 http://sinonjs.org/ and download the current ...

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