Book Image

Backbone.js Patterns and Best Practices

By : Swarnendu De
Book Image

Backbone.js Patterns and Best Practices

By: Swarnendu De

Overview of this book

Table of Contents (19 chapters)
Backbone.js Patterns and Best Practices
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Precompiling Templates on the Server Side
Index

Using test spies, stubs, and mocks with SinonJS


We use unit testing to test one component of an application. That component can be a function, an object, a variable, or any outcome which is not known yet, and your unit test wants to make sure whether that particular component is working fine or not. Often, besides testing separate components, you may find testing the behavior of your methods is of the same importance. For example, how many times a method is called, what it returns, whether it has thrown any exception, what arguments it is called with, and so on. To perform these types of behavioral testing, we use test spies, stubs, and mocks.

There are few testing libraries which support test spies, stubs, and mocks. However, we found SinonJS quite easy to work with and robust as well. SinonJS works seamlessly with QUnit and you can use it with or without QUnit too. The definition of SinonJS, as given on their website, is as follows:

Standalone test spies, stubs and mocks for JavaScript....