QUnit.module()


QUnit.module( name, lifecycle )

Description: Group related tests under a single label.

All tests that occur after a call to QUnit.module() will be grouped into that module, until other QUnit.module() is called. The test names will all be preceded by the module name in the test results. You can then use that module name to select tests to run.

You can specify code to run before and after each test using the lifecycle argument.

Examples:

Example: Use the QUnit.module() function to group tests together:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
QUnit.module( "group a" );
QUnit.test( "a basic test example", function( assert ) {
assert.ok( true, "this test is fine" );
});
QUnit.test( "a basic test example 2", function( assert ) {
assert.ok( true, "this test is fine" );
});
QUnit.module( "group b" );
QUnit.test( "a basic test example 3", function( assert ) {
assert.ok( true, "this test is fine" );
});
QUnit.test( "a basic test example 4", function() {
assert.ok( true, "this test is fine" );
});

Example: A sample for using the setup and teardown callbacks

1
2
3
4
5
6
7
8
QUnit.module( "module A", {
setup: function() {
// prepare something for all following tests
},
teardown: function() {
// clean up after each test
}
});