Debian Codegraph @

tests/errback/errback.html

raw
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <title>almond: errback Test</title>
5 <script type="text/javascript" src="../doh/runner.js"></script>
6 <script type="text/javascript" src="../doh/_browserRunner.js"></script>
7 <script type="text/javascript" src="../../almond.js"></script>
8 <script type="text/javascript">
9 var master = new doh.Deferred();
10 count = 0;
11
12 function done() {
13 count += 1;
14 if (count === 2) {
15 master.callback(true);
16 }
17 }
18
19 //Register the test
20 doh.register(
21 "errback",
22 [
23 {
24 name: "errback",
25 timeout: 2000,
26 runTest: function () {
27 return master;
28 }
29 }
30 ]
31 );
32 doh.run();
33
34
35 define('plug', function () {
36 return {
37 load: function (id, require, load, config) {
38 require([id], load, function (err) {
39 throw err;
40 });
41 }
42 }
43 })
44
45 define('c', ['plug!foo'], function (foo) {
46 return {
47 name: 'c',
48 foo: foo
49 };
50 });
51
52 define('fu/a', ['require'], function(require){
53 var myC = null;
54
55 require(['c'], function (c) {
56 myC = c;
57 doh.is('c', myC.name);
58 doh.is('foo', myC.foo.name);
59 done();
60 }, function (err) {
61 //This should not be triggered
62 throw err;
63 });
64
65 //Make sure require is async
66 doh.is(null, myC);
67
68 return {
69 name: 'fu/a'
70 };
71 });
72
73 define('foo', {
74 name: 'foo'
75 });
76
77 define('foo/bar/c',['../../fu/a'], function(v){
78 return {
79 name: 'foo/bar/c',
80 fuA: v
81 };
82 });
83
84 define('foo/b',['require', './bar/c'], function(require){
85 return {
86 name: 'foo/b',
87 barC: require('./bar/c')
88 };
89 });
90
91 define('main', ['./foo/b'], function(v){
92 return {
93 name: 'main',
94 fooB: v
95 };
96 });
97
98 var myMain = null;
99
100 require(['main'], function(main){
101 myMain = main;
102 doh.is('main', myMain.name);
103 doh.is('foo/b', myMain.fooB.name);
104 doh.is('foo/bar/c', myMain.fooB.barC.name);
105 doh.is('fu/a', myMain.fooB.barC.fuA.name);
106 done();
107 }, function (err) {
108 //This should never be reached, but it should not cause
109 //a problem either.
110 throw err;
111 });
112
113 //Make sure require is async
114 doh.is(null, myMain);
115
116 </script>
117 </head>
118 <body>
119 <h1>almond: errback Test</h1>
120
121 <p>Test the use of errbacks in a require call. While almond does not
122 support calling an errback (all modules should be built in and usable),
123 almond should not throw any errors if they are used.</p>
124
125 <p>Check console for messages</p>
126 </body>
127 </html>