2429facbf112e308c532cf8427d73c4d17d9706e
[WebKit-https.git] / LayoutTests / js / dom / Promise-types.html
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <meta charset="utf-8">
5 <script src="../../resources/js-test-pre.js"></script>
6 </head>
7 <body>
8 <script>
9
10 description("Promises - Test basic types / exceptions.");
11
12 // window.jsTestIsAsync = true;
13
14
15 // Promise
16 debug("");
17 debug("Promises");
18 debug("");
19
20 // Promises should be of type Promise.
21
22 var aPromise = new Promise(function(resolve, reject) { resolve(1); });
23
24 debug("aPromise = new Promise(...)")
25 shouldBeType("aPromise", "Promise");
26 shouldBe("String(aPromise)", "'[object Promise]'");
27
28 shouldBeDefined("aPromise.then");
29 shouldBeType("aPromise.then", "Function");
30 shouldBe("aPromise.then.length", "2");
31 shouldBeDefined("aPromise.catch");
32 shouldBeType("aPromise.catch", "Function");
33 shouldBe("aPromise.catch.length", "1");
34
35 var aPromise2 = Promise(function(resolve, reject) { resolve(1); });
36
37 debug("aPromise2 = Promise(...)")
38 shouldBeType("aPromise2", "Promise");
39 shouldBe("String(aPromise2)", "'[object Promise]'");
40
41 // Promise constructor
42 debug("");
43 debug("Promise constructor");
44 debug("");
45
46 // Need at least one parameter.
47 shouldBe("Promise.length", "1");
48 shouldThrow("new Promise()");
49 shouldThrow("Promise()");
50
51 // Parameter must be a function.
52 shouldThrow("new Promise(1)", "'TypeError: Promise constructor takes a function argument'");
53 shouldThrow("new Promise('hello')", "'TypeError: Promise constructor takes a function argument'");
54 shouldThrow("new Promise([])", "'TypeError: Promise constructor takes a function argument'");
55 shouldThrow("new Promise({})", "'TypeError: Promise constructor takes a function argument'");
56 shouldThrow("new Promise(null)", "'TypeError: Promise constructor takes a function argument'");
57 shouldThrow("new Promise(undefined)", "'TypeError: Promise constructor takes a function argument'");
58
59 shouldThrow("Promise(1)", "'TypeError: Promise constructor takes a function argument'");
60 shouldThrow("Promise('hello')", "'TypeError: Promise constructor takes a function argument'");
61 shouldThrow("Promise([])", "'TypeError: Promise constructor takes a function argument'");
62 shouldThrow("Promise({})", "'TypeError: Promise constructor takes a function argument'");
63 shouldThrow("Promise(null)", "'TypeError: Promise constructor takes a function argument'");
64 shouldThrow("Promise(undefined)", "'TypeError: Promise constructor takes a function argument'");
65
66 // Promise statics
67 debug("");
68 debug("Promise statics");
69 debug("");
70
71
72 // Need at least one parameter.
73 shouldBeType("Promise.resolve", "Function");
74 shouldBe("Promise.resolve.length", "1");
75 shouldNotThrow("Promise.resolve(1)");
76
77 shouldBeType("Promise.reject", "Function");
78 shouldBe("Promise.reject.length", "1");
79 shouldNotThrow("Promise.reject(1)");
80
81 // Should return Promise objects.
82 shouldBeType("Promise.resolve(1)", "Promise");
83 shouldBeType("Promise.reject(1)", "Promise");
84
85 </script>
86 <script src="../../resources/js-test-post.js"></script>
87 </body>
88 </html>