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

Testing with QUnit


QUnit (http://qunitjs.com), a lightweight unit testing framework maintained by the jQuery team, which is quite easy to work with compared to other frameworks. Discussing QUnit in complete detail is beyond the scope of this book, but we will learn about the simple features of it and explore how we can use it with our Backbone components.

Assertions are the most essential elements of any unit test framework. You need to compare your actual implementation values to the results that the test produces. Assertions are the methods that serve this comparison functionality. QUnit has only eight assertions; we are going to use some of them in the next section. Let's discuss a few of them here:

  • ok (state, message): This passes if the first argument is true

  • equal (actual, expected, message): This returns true if actual and expected are equal

  • deepEqual (actual, expected, message): This is a deep recursive-comparison assertion, working on primitive types, arrays, objects, regular expressions...