-
Notifications
You must be signed in to change notification settings - Fork 14
/
BeforeAfterTaskTest.js
42 lines (34 loc) · 1.21 KB
/
BeforeAfterTaskTest.js
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
31
32
33
34
35
36
37
38
39
40
41
42
var Zone = require('../lib/Setup.js').enable();
exports.testBeforeTask = function(test) {
test.expect(2);
var beforeHook = function() { test.ok(true, 'expecting a call'); };
zone.create(function() { test.ok(test, 'running the main function'); },
{beforeTask: beforeHook});
test.done();
};
exports.testBeforeTaskWithError = function(test) {
test.expect(3);
var beforeHook = function() {
test.equal(zone.name, 'ChildZone');
test.ok(true, 'expecting a call');
throw new Error('expected error');
};
//success called even tough code in main function did not run
//and before hook threw error
var successCallback = function(err) {
test.strictEqual(zone, zone.root);
test.done();
};
var childZone = zone.create(function ChildZone() {
//never gets run
test.equal(global.zone.name, 'ChildZone');
test.ok(test, 'running the main function');
}, {beforeTask: beforeHook, successCallback: successCallback});
};
exports.testAfterTask = function(test) {
test.expect(2);
var afterHook = function() { test.ok(true, 'expecting a call'); };
zone.create(function() { test.ok(test, 'running the main function'); },
{afterTask: afterHook});
test.done();
};