You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/lifecycle.md
+45-19Lines changed: 45 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,18 +15,14 @@ The execution order of module hooks in QUnit.
15
15
</p>
16
16
17
17
<figure>
18
-
<img src="/resources/qunit-lifecycle-hooks-order.svg" width="676" height="901" alt="" title="Imagine a test suite that uses global hooks,
19
-
and has a module called Parent that uses hooks and contains one test called Foo,
20
-
and a nested module called Child that also uses hooks and contains one test called Bar.
21
-
The execution order is as follows:
22
-
1. The Parent module runs its before hook exactly once.
23
-
2. Every test in the Parent module inherits the test context from this before hook.
24
-
3. This repeats for every test in the Parent module: call global beforeEach, parent beforeEach, actual test (Foo), parent afterEach, and lastly the global afterEach.
25
-
4. The Child module inherits context from the Parent's before hook, and runs its own before hook exactly once.
26
-
5. Every test in the Child module inherits test context from this before hook.
27
-
6. This repeats for every test in the Child module: call the global beforeEach, parent beforeEach, child beforeEach, actual test (Bar), child afterEach, parent afterEach, and lastly the global afterEach.
18
+
<img src="/resources/qunit-lifecycle-hooks-order.svg" width="676" height="901" alt="" title="Imagine a test suite with global hooks, and a Parent and Child module that use hooks also. The execution order is:
19
+
1. Parent module runs the before hook.
20
+
2. Every test in the Parent module inherits context from the before hook, and repeats as follows: call global beforeEach, parent beforeEach, the actual test, parent afterEach, and lastly the global afterEach.
21
+
3. The Child module inherits context from the Parent before hook, and then runs its own before hook.
22
+
4. Every test in the Child module inherits context from this before hook, and repeats as follows: call global beforeEach, parent beforeEach, child beforeEach, the actual test, child afterEach, parent afterEach, and lastly the global afterEach.
@@ -38,7 +34,7 @@ You can define the following hooks via `QUnit.module()`:
38
34
*`afterEach`: Add a callback after every test.
39
35
*`after`: Add a callback after the last test, once per module.
40
36
41
-
Hooks that run _before_ a test, are executed in the order that they are added (from outer-most to inner-most). This means that utilities and fixtures provided global hooks are safe to use during all tests, and also during the beforeEach hooks of all modules. Likewise, the same is true between a parent module and its child modules.
37
+
Hooks that run _before_ a test, are executed in the order that they are added (from outer-most to inner-most). This means that utilities and fixtures provided by global hooks are safe to use during all tests, and also during the beforeEach hooks of all modules. Likewise, the same is true between a parent module and its child modules.
42
38
43
39
For example:
44
40
@@ -105,7 +101,7 @@ QUnit.module('Foo', function (hooks) {
105
101
c ='Stranger';
106
102
});
107
103
108
-
QUnit.test('nested example', (assert)=> {
104
+
QUnit.test('nested example', function(assert) {
109
105
assert.equal(a, 'Hello to this');
110
106
assert.equal(b, 'world');
111
107
assert.equal(MyApp.greeting(), 'Hello to this world');
Each test starts with a fresh copy of the test context as provided by the module. This is generally an empty object. The test context is available as `this` inside any [`QUnit.test()`](./api/QUnit/test.md) function or hook callbacks.
162
+
Each test starts with a fresh copy of the test context as provided by the module. This is generally an empty object. The test context is available as `this` inside any [`QUnit.test()`](./api/QUnit/test.md) function or hook callback.
167
163
168
164
At the end of every test, changes to the test context are automatically reset (e.g. changes by tests or hooks). The next test will start with a fresh context provided by the module.
169
165
@@ -210,30 +206,60 @@ QUnit.module('Machine Maker', function (hooks) {
0 commit comments