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 window.jsTestIsAsync = true; | |
11 | |
12 description('Test Promise.'); | |
13 | |
14 var thisInInit; | |
15 var resolve, reject; | |
16 var promise = new Promise(function(newResolve, newReject) { | |
17 thisInInit = this; | |
18 resolve = newResolve; | |
19 reject = newReject; | |
20 }); | |
21 | |
22 shouldBeTrue('promise instanceof Promise'); | |
23 shouldBe('promise.constructor', 'Promise'); | |
24 shouldBeFalse('thisInInit === promise'); | |
25 shouldBeTrue('thisInInit === window'); | |
26 shouldBeTrue('resolve instanceof Function'); | |
27 shouldBeTrue('reject instanceof Function'); | |
28 | |
29 shouldThrow('new Promise()', '"TypeError: Promise constructor takes a function a
rgument"'); | |
30 shouldThrow('new Promise(37)', '"TypeError: Promise constructor takes a function
argument"'); | |
31 | |
32 shouldNotThrow('promise = new Promise(function() { throw Error("foo"); })'); | |
33 promise.then(undefined, function(result) { | |
34 window.result = result; | |
35 shouldBeEqualToString('result.message', 'foo'); | |
36 }); | |
37 | |
38 new Promise(function(resolve) { | |
39 resolve("hello"); | |
40 throw Error("foo"); | |
41 }).then(function(result) { | |
42 window.result = result; | |
43 testPassed('fulfilled'); | |
44 shouldBeEqualToString('result', 'hello'); | |
45 finishJSTest(); | |
46 }, function(result) { | |
47 window.result = result; | |
48 testFailed('rejected'); | |
49 finishJSTest(); | |
50 }); | |
51 | |
52 </script> | |
53 </body> | |
54 </html> | |
OLD | NEW |