QUnit.module( name [, hooks ] [, nested ] )
Description: Group related tests under a single label.
-
QUnit.module( name [, hooks ] [, nested ] )
-
nameType: StringLabel for this group of tests.
-
hooksType: PlainObjectCallbacks to run during test execution.
-
beforeType: Function()Runs before the first test.
-
beforeEachType: Function()Runs before each test.
-
afterEachType: Function()Runs after each test.
-
afterType: Function()Runs after the last test. If additional tests are defined after the module's queue has emptied, it will not run this hook again.
-
-
nestedA callback with grouped tests and nested modules to run under the current module label.
-
You can use the module name to organize, select, and filter tests to run.
All tests inside a module callback function will be grouped into that module. The test names will all be preceded by the module name in the test results. Other modules can be nested inside this callback function, where their tests' names will be labeled by their names recursively prefixed by their parent modules.
If QUnit.module is defined without a nested callback argument, all subsequently defined tests will be grouped into the module until another module is defined.
Modules with test group functions allow you to define nested modules, and QUnit will run tests on the parent module before going deep on the nested ones, even if they're declared first. Additionally, any hook callbacks on a parent module will wrap the hooks on a nested module. In other words, before and beforeEach callbacks will form a queue while the afterEach and after callbacks will form a stack.
You can specify code to run before and after tests using the hooks argument, and also to create properties that will be shared on the testing context. Any additional properties on the hooks object will be added to that context. The hooks argument is still optional if you call QUnit.module with a callback argument.
The module's callback is invoked with the test environment as its this context, with the environment's properties copied to the module's tests, hooks, and nested modules. Note that changes on tests' this are not preserved between sibling tests, where this will be reset to the initial value for each test.
Examples:
Use the QUnit.module() function to group tests together:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
|
Use the QUnit.module() function to group tests together:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
|
A sample for using the before, beforeEach, afterEach, and after callbacks
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
|
Hooks share the same context as their respective test
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
|
Hooks stack on nested modules
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
|