O'Reilly logo

CoffeeScript Application Development Cookbook by Mike Hatfield

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

Stubbing and mocking with Sinon

In this recipe, we will use a JavaScript library called Sinon to create test doubles to help improve our tests.

Test doubles are fake objects that replace actual dependencies in our tests. Why would you want to use a mocking library? Some of the benefits of using a library such as Sinon include the following:

  • They allow us to focus on our code under test without having to worry that its dependencies are working correctly, or even exist
  • They allow us to speed up our tests by faking out network calls, database access, and other tasks that slow our tests down

Getting ready

In this section, we create and use stubs in our tests.

A stub is a fake object that provides stand-in functionality of an external dependency of our object ...

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