Organizing tests

QUnit provides two levels of test grouping named after their respective function calls: module() and test(). The module is like a general category under which the tests will be run; the test is actually a set of tests; the function takes a callback in which all of that test's specific unit tests are run. We'll group our tests by the chapter topic, placing the code in our test/test.js file:

module('Selecting');
test('Child Selector', function() {
  ok(true, 'Placeholder is entered');
});
test('Attribute Selectors', function() {
  ok(true, 'Placeholder is entered');
});
module('Ajax');

Listing B.1

It's not necessary to set up the file with this test structure, but it's good to have some overall structure in mind. In addition to the ...

Get Learning jQuery - Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.