OLD | NEW |
---|---|
1 /* | 1 /* |
2 * worker-test-harness should be considered a temporary polyfill around | 2 * worker-test-harness should be considered a temporary polyfill around |
3 * testharness.js for supporting Service Worker based tests. It should not be | 3 * testharness.js for supporting Service Worker based tests. It should not be |
4 * necessary once the test harness is able to drive worker based tests natively. | 4 * necessary once the test harness is able to drive worker based tests natively. |
5 * See https://github.com/w3c/testharness.js/pull/82 for status of effort to | 5 * See https://github.com/w3c/testharness.js/pull/82 for status of effort to |
6 * update upstream testharness.js. Once the upstreaming is complete, tests that | 6 * update upstream testharness.js. Once the upstreaming is complete, tests that |
7 * reference worker-test-harness should be updated to directly import | 7 * reference worker-test-harness should be updated to directly import |
8 * testharness.js. | 8 * testharness.js. |
9 */ | 9 */ |
10 | 10 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
77 // boilerplate for testing with promises. | 77 // boilerplate for testing with promises. |
78 function promise_test(func, name, properties) { | 78 function promise_test(func, name, properties) { |
79 properties = properties || {}; | 79 properties = properties || {}; |
80 var test = async_test(name, properties); | 80 var test = async_test(name, properties); |
81 Promise.resolve(test.step(func, test, test)) | 81 Promise.resolve(test.step(func, test, test)) |
82 .then(function() { test.done(); }) | 82 .then(function() { test.done(); }) |
83 .catch(test.step_func(function(value) { | 83 .catch(test.step_func(function(value) { |
84 throw value; | 84 throw value; |
85 })); | 85 })); |
86 } | 86 } |
87 | |
88 // Returns a promise that fulfills after the provided |promise| is fulfilled. | |
89 // The |test| succeeds only if |promise| throws an exception matching |code|. | |
90 // The optional |description| describes the test being performed. | |
91 // E.g.: | |
92 // assert_promise_throws( | |
93 // new Promise(...), // something that should throw an exception. | |
94 // 'NotFoundError', | |
95 // 'Should throw NotFoundError.'); | |
96 function assert_promise_throws(promise, code, description) { | |
97 return promise.then( | |
98 function() { | |
99 throw 'assert_promise_throws: ' + description + ' Promise did now throw.'; | |
jsbell
2014/08/27 22:28:23
Typo: now -> not
asanka
2014/08/28 00:02:56
Done.
| |
100 }, | |
101 function(e) { | |
102 if (code in self) { | |
103 // If |code| is a JavaScript error exposed in the global object, then | |
104 // require that the thrown exception be of that type. | |
105 assert_class_string(e, code, description); | |
jsbell
2014/08/27 21:56:47
This doesn't work - the Error subclasses like Type
asanka
2014/08/28 00:02:56
Ah. Hack removed. We are now calling assert_promis
| |
106 } else { | |
107 assert_throws(code, function() { throw e; }, description); | |
108 } | |
109 }); | |
110 } | |
OLD | NEW |