O'Reilly logo

Learning jQuery Third Edition by Karl Swedberg, Jonathan Chaffer

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

Organizing tests

QUnit provides two levels of 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 that takes a callback in which all of that test's specific unit tests are run. We will group our tests by the chapter topic, placing the code in our test/test.js file:

module('Selecting');

test('Child Selector', function() {
  // tests go here
});

test('Attribute Selectors', function() {
  // tests go here
});

module('Ajax');

It is not necessary to set up the file with the test structure, but it is good to have an overall structure in mind. Notice that our modules and tests do not need to be placed inside a $(document).ready() ...

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