Chapter 8. Unit Test, Stub, Spy, and Mock Your App
Majority of developers believe that testing is essential, but in reality only a few of them actually go for test-driven development. Testing falls under one of the best practices of the JavaScript development process. Hence, we decided to include a chapter on how to unit test Backbone-based applications.
A number of popular testing libraries, such as QUnit
, Jasmine
, Mocha
, and SinonJS
, are available to unit test JavaScript applications. In this chapter, we are going to show you how to test with QUnit
, the simplest yet robust testing platform, which is pretty easy to learn as well. In the latter part, we will look into SinonJS
to learn test spies, stubs, and mocks. Together, QUnit
and SinonJS
create a strong tool to test every part of your app. The main points to be discussed in this chapter are as follows:
Why unit testing is important: Testing is a habit. Continuing this along with development may take some extra time initially, but it is...