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 trueequal (actual, expected, message)
: This returns true ifactual
andexpected
are equaldeepEqual (actual, expected, message)
: This is a deep recursive-comparison assertion, working on primitive types, arrays, objects, regular expressions...