O'Reilly logo

Developing Backbone.js Applications by Adnan Osmani

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

Chapter 13. Jasmine

One definition of unit testing is the process of taking the smallest piece of testable code in an application, isolating it from the remainder of your codebase, and determining if it behaves exactly as expected.

For an application to be considered well tested, each function should ideally have its own separate unit tests where it’s tested against the different conditions you expect it to handle. All tests must pass before functionality is considered complete. This allows developers to modify a unit of code and its dependencies with a level of confidence about whether these changes have caused any breakage.

A basic example of unit testing is where a developer asserts that passing specific values to a sum function results in the correct value being returned. For an example more relevant to this book, we may wish to assert that adding a new todo item to a list correctly adds a model of a specific type to a Todos collection.

When you are building modern web applications, it’s typically considered a best practice to include automated unit testing as a part of your development process. In the following chapters, we are going to look at three different solutions for unit-testing your Backbone.js apps: Jasmine, QUnit, and SinonJS.

Behavior-Driven Development

In this chapter, we’ll be taking a look at how to unit-test Backbone applications using a popular JavaScript testing framework called Jasmine from Pivotal Labs.

Jasmine describes itself as a behavior-driven development, ...

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