1 | define([ |
---|
2 | "doh/main", |
---|
3 | "dojo/Deferred" |
---|
4 | ], function(doh, Deferred){ |
---|
5 | var tests = { |
---|
6 | "always() will be invoked for resolution and rejection": function(t){ |
---|
7 | var obj = {}; |
---|
8 | var deferred1 = new Deferred(); |
---|
9 | var thenResult, alwaysResult; |
---|
10 | deferred1.promise.then(function(result){ thenResult = result; }); |
---|
11 | deferred1.promise.always(function(result){ alwaysResult = result; }); |
---|
12 | deferred1.resolve(obj); |
---|
13 | t.t(alwaysResult === obj); |
---|
14 | t.t(alwaysResult === thenResult); |
---|
15 | |
---|
16 | var deferred2 = new Deferred(); |
---|
17 | var thenResult2, alwaysResult2; |
---|
18 | deferred2.promise.then(null, function(result){ thenResult2 = result; }); |
---|
19 | deferred2.promise.always(function(result){ alwaysResult2 = result; }); |
---|
20 | deferred2.reject(obj); |
---|
21 | t.t(alwaysResult2 === obj); |
---|
22 | t.t(alwaysResult2 === thenResult2); |
---|
23 | }, |
---|
24 | |
---|
25 | "otherwise(âŠ) is equivalent to then(null, âŠ)": function(t){ |
---|
26 | var obj = {}; |
---|
27 | var thenResult, otherwiseResult; |
---|
28 | this.deferred.then(null, function(result){ thenResult = result; }); |
---|
29 | this.deferred.promise.otherwise(function(result){ otherwiseResult = result; }); |
---|
30 | this.deferred.reject(obj); |
---|
31 | t.t(otherwiseResult === obj); |
---|
32 | t.t(otherwiseResult === thenResult); |
---|
33 | }, |
---|
34 | |
---|
35 | "trace() returns the same promise": function(t){ |
---|
36 | var promise = this.deferred.promise.trace(); |
---|
37 | t.t(promise === this.deferred.promise); |
---|
38 | }, |
---|
39 | |
---|
40 | "traceRejected() returns the same promise": function(t){ |
---|
41 | var promise = this.deferred.promise.traceRejected(); |
---|
42 | t.t(promise === this.deferred.promise); |
---|
43 | } |
---|
44 | }; |
---|
45 | |
---|
46 | var wrapped = []; |
---|
47 | for(var name in tests){ |
---|
48 | wrapped.push({ |
---|
49 | name: name, |
---|
50 | setUp: setUp, |
---|
51 | runTest: tests[name] |
---|
52 | }); |
---|
53 | } |
---|
54 | |
---|
55 | function setUp(){ |
---|
56 | this.deferred = new Deferred; |
---|
57 | } |
---|
58 | |
---|
59 | doh.register("tests.promise.Promise", wrapped); |
---|
60 | }); |
---|