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. | |
asanka
2014/10/10 19:39:11
Could you mention here that testharness-helpers.js
Marijn Kruisselbrink
2014/10/10 20:32:55
Done.
| |
5 */ | |
6 | |
7 // 'promise_test' is a new kind of testharness test that handles some | |
8 // boilerplate for testing with promises. | |
9 function promise_test(func, name, properties) { | |
10 properties = properties || {}; | |
11 var test = async_test(name, properties); | |
12 Promise.resolve(test.step(func, test, test)) | |
13 .then(function() { test.done(); }) | |
14 .catch(test.step_func(function(value) { | |
15 throw value; | |
16 })); | |
17 } | |
18 | |
19 // Returns a promise that fulfills after the provided |promise| is fulfilled. | |
20 // The |test| succeeds only if |promise| rejects with an exception matching | |
21 // |code|. Accepted values for |code| follow those accepted for assert_throws(). | |
22 // The optional |description| describes the test being performed. | |
23 // E.g.: | |
24 // assert_promise_rejects( | |
25 // new Promise(...), // something that should throw an exception. | |
26 // 'NotFoundError', | |
27 // 'Should throw NotFoundError.'); | |
28 // | |
29 // assert_promise_rejects( | |
30 // new Promise(...), | |
31 // new TypeError(), | |
32 // 'Should throw TypeError'); | |
33 function assert_promise_rejects(promise, code, description) { | |
34 return promise.then( | |
35 function() { | |
36 throw 'assert_promise_rejects: ' + description + ' Promise did not throw.' ; | |
asanka
2014/10/10 19:39:11
Nit: 'Promise did not reject.'
Marijn Kruisselbrink
2014/10/10 20:32:55
Done.
| |
37 }, | |
38 function(e) { | |
39 if (code !== undefined) { | |
40 assert_throws(code, function() { throw e; }, description); | |
41 } | |
42 }); | |
43 } | |
OLD | NEW |