]> git.pond.sub.org Git - eow/blob - static/dojo-release-1.1.1/dojo/tests/_base/Deferred.js
Comment class stub
[eow] / static / dojo-release-1.1.1 / dojo / tests / _base / Deferred.js
1 if(!dojo._hasResource["tests._base.Deferred"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
2 dojo._hasResource["tests._base.Deferred"] = true;
3 dojo.provide("tests._base.Deferred");
4
5 doh.register("tests._base.Deferred", 
6         [
7
8                 function callback(t){
9                         var nd = new dojo.Deferred();
10                         var cnt = 0;
11                         nd.addCallback(function(res){
12                                 doh.debug("debug from dojo.Deferred callback");
13                                 return res;
14                         });
15                         nd.addCallback(function(res){
16                                 // t.debug("val:", res);
17                                 cnt+=res;
18                                 return cnt;
19                         });
20                         nd.callback(5);
21                         // t.debug("cnt:", cnt);
22                         t.assertEqual(cnt, 5);
23                 },
24
25                 function callback_extra_args(t){
26                         var nd = new dojo.Deferred();
27                         var cnt = 0;
28                         nd.addCallback(dojo.global, function(base, res){ cnt+=base; cnt+=res; return cnt; }, 30);
29                         nd.callback(5);
30                         t.assertEqual(cnt, 35);
31                 },
32
33                 function errback(t){
34                         var nd = new dojo.Deferred();
35                         var cnt = 0;
36                         nd.addErrback(function(val){
37                                 return ++cnt;
38                         });
39                         nd.errback();
40                         t.assertEqual(cnt, 1);
41                 },
42
43                 function callbackTwice(t){
44                         var nd = new dojo.Deferred();
45                         var cnt = 0;
46                         nd.addCallback(function(res){
47                                 return ++cnt;
48                         });
49                         nd.callback();
50                         t.assertEqual(cnt, 1);
51                         var thrown = false;
52                         try{
53                                 nd.callback();
54                         }catch(e){
55                                 thrown = true;
56                         }
57                         t.assertTrue(thrown);
58                 },
59
60                 function addBoth(t){
61                         var nd = new dojo.Deferred();
62                         var cnt = 0;
63                         nd.addBoth(function(res){
64                                 return ++cnt;
65                         });
66                         nd.callback();
67                         t.assertEqual(cnt, 1);
68
69                         // nd.callback();
70                         // t.debug(cnt);
71                         // t.assertEqual(cnt, 1);
72                 }
73         ]
74 );
75
76 }