tracer.js
2.3 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
define([
"doh/main",
"dojo/Deferred",
"dojo/promise/tracer"
], function(doh, Deferred, tracer){
var tests = {
"trace() resolved": function(t){
var td = new doh.Deferred;
var obj = {};
this.handles.push(tracer.on("resolved", function(value){
t.t(value === obj);
td.callback(true);
}));
this.deferred.promise.trace();
this.deferred.resolve(obj);
return td;
},
"trace() rejected": function(t){
var td = new doh.Deferred;
var obj = {};
this.handles.push(tracer.on("rejected", function(error){
t.t(error === obj);
td.callback(true);
}));
this.deferred.promise.trace();
this.deferred.reject(obj);
return td;
},
"trace() progress": function(t){
var td = new doh.Deferred;
var obj = {};
this.handles.push(tracer.on("progress", function(update){
t.t(update === obj);
td.callback(true);
}));
this.deferred.promise.trace();
this.deferred.progress(obj);
return td;
},
"passing extra arguments to trace()": function(t){
var td = new doh.Deferred;
var obj = {};
this.handles.push(tracer.on("resolved", function(value, arg1, arg2){
t.t(value === obj);
t.is(arg1, "test");
t.t(arg2 === obj);
td.callback(true);
}));
this.deferred.promise.trace("test", obj);
this.deferred.resolve(obj);
return td;
},
"traceRejected()": function(t){
var td = new doh.Deferred;
var obj = {};
this.handles.push(tracer.on("rejected", function(error){
t.t(error === obj);
td.callback(true);
}));
this.deferred.promise.traceRejected();
this.deferred.reject(obj);
return td;
},
"passing extra arguments": function(t){
var td = new doh.Deferred;
var obj = {};
this.handles.push(tracer.on("rejected", function(error, arg1, arg2){
t.t(error === obj);
t.is(arg1, "test");
t.t(arg2 === obj);
td.callback(true);
}));
this.deferred.promise.traceRejected("test", obj);
this.deferred.reject(obj);
return td;
}
};
var wrapped = [];
for(var name in tests){
wrapped.push({
name: name,
setUp: setUp,
tearDown: tearDown,
runTest: tests[name]
});
}
function setUp(){
this.handles = [];
this.deferred = new Deferred;
}
function tearDown(){
while(this.handles.length){
this.handles.pop().remove();
}
}
doh.register("tests.promise.tracer", wrapped);
});