Title: Backbone.js Testing
Author: Ryan Roemer
Reading period: October 2013
Backbone.js Testing is a short, dense introduction
Mocha, Chai, and Sinon.JS.
Although the author uses a sample application
of a personal note manager written with Backbone.js
throughout the book, much of the material
Mocha is a test framework that can be executed in the browser or by Node.js,
which runs your tests.
Chai is a framework-agnostic TDD/BDD assertion library.
They complement each other and the author does a good job of explaining
when and how to use each.
I've written a lot of tests in Python (unittest and mock, primarily)
was both limited and years out of date.
with new browser frameworks and Node packages springing up everywhere.
Mocha, Chai, and Sinon meet those challenges, though they can't take away all the pain.
The author describes how to test Backbone models, views, and collections;
dealing with asynchrony;
provides useful testing heuristics, including isolating components to reduce dependencies;
when to use stubs and mocks and fake servers;
and test automation with PhantomJS.
He does not, however, teach you Backbone.js itself; for that, you'll need another book.
There are a few areas which I thought were dealt with too lightly.
There's no real discussion of Test-driven_development or
which provide the intellectual foundations of much of the book.
Nor does he have much to say about testability and how to make
legacy code more testable.
The sample Notes app has plenty of testing seams
(much of this falls naturally out of the architecture of Backbone);
other people's apps are not so lucky.
The chapter on automation is extremely terse—it could be expanded into a very large book!—but it does provide useful indicators to many areas for exploration.
I learned a lot from this book and I have no hesitation in recommending it.
Disclosure: Thanks to Ryan Roemer and Packt for a review copy of this book.