OLD | NEW |
| (Empty) |
1 <!DOCTYPE html> | |
2 <html> | |
3 <head> | |
4 <script src="../../resources/js-test.js"></script> | |
5 </head> | |
6 <body> | |
7 <div id="description"></div> | |
8 <div id="console"></div> | |
9 <script> | |
10 description('Test Promise.'); | |
11 | |
12 window.jsTestIsAsync = true; | |
13 | |
14 var resolve; | |
15 var promise = new Promise(function (r) {resolve = r;}); | |
16 var operation; | |
17 | |
18 promise.then(function(result) { // fulfilled - continue | |
19 testPassed('fulfilled'); | |
20 window.result = result; | |
21 shouldBeEqualToString('result', 'hello'); | |
22 return 'hello2'; | |
23 }, function() { | |
24 testFailed('rrejected'); | |
25 }).then() // pass through | |
26 .then(function(result) { // fulfilled - throw an exception | |
27 testPassed('fulfilled'); | |
28 window.result = result; | |
29 shouldBeEqualToString('result', 'hello2'); | |
30 throw 'error'; | |
31 }, function() { | |
32 testFailed('rejected'); | |
33 }).then(function() { // rejected - throw an exception | |
34 testFailed('fulfilled'); | |
35 }, function(result) { | |
36 testPassed('rejected'); | |
37 window.result = result; | |
38 shouldBeEqualToString('result', 'error'); | |
39 throw 'error2'; | |
40 }).then() // pass through | |
41 .then(function() { // rejected - recover | |
42 testFailed('fulfilled'); | |
43 }, function(result) { | |
44 testPassed('rejected'); | |
45 window.result = result; | |
46 shouldBeEqualToString('result', 'error2'); | |
47 return 'recovered'; | |
48 }).then(function(result) { // fulfilled - the last | |
49 testPassed('fulfilled'); | |
50 window.result = result; | |
51 shouldBeEqualToString('result', 'recovered'); | |
52 shouldBeEqualToString('operation', 'asynchronous'); | |
53 finishJSTest(); | |
54 }, function() { | |
55 testFailed('rejected'); | |
56 finishJSTest(); | |
57 }); | |
58 | |
59 operation = 'synchronous'; | |
60 resolve('hello'); | |
61 | |
62 // The chain should be executed asynchronously. | |
63 operation = 'asynchronous'; | |
64 | |
65 </script> | |
66 </body> | |
67 </html> | |
OLD | NEW |