OLD | NEW |
| (Empty) |
1 /* | |
2 * testharness-helpers contains various useful extensions to testharness.js to | |
3 * allow them to be used across multiple tests before they have been | |
4 * upstreamed. This file is intended to be usable from both document and worker | |
5 * environments, so code should for example not rely on the DOM. | |
6 */ | |
7 | |
8 // Returns a promise that fulfills after the provided |promise| is fulfilled. | |
9 // The |test| succeeds only if |promise| rejects with an exception matching | |
10 // |code|. Accepted values for |code| follow those accepted for assert_throws(). | |
11 // The optional |description| describes the test being performed. | |
12 // | |
13 // E.g.: | |
14 // assert_promise_rejects( | |
15 // new Promise(...), // something that should throw an exception. | |
16 // 'NotFoundError', | |
17 // 'Should throw NotFoundError.'); | |
18 // | |
19 // assert_promise_rejects( | |
20 // new Promise(...), | |
21 // new TypeError(), | |
22 // 'Should throw TypeError'); | |
23 function assert_promise_rejects(promise, code, description) { | |
24 return promise.then( | |
25 function() { | |
26 throw 'assert_promise_rejects: ' + description + ' Promise did not reject.
'; | |
27 }, | |
28 function(e) { | |
29 if (code !== undefined) { | |
30 assert_throws(code, function() { throw e; }, description); | |
31 } | |
32 }); | |
33 } | |
OLD | NEW |