(run, errorType, message)
| 7 | // Do not install `AsyncFunction` constructor on global object |
| 8 | |
| 9 | function assertThrowsAsync(run, errorType, message) { |
| 10 | var actual; |
| 11 | var hadValue = false; |
| 12 | var hadError = false; |
| 13 | var promise = run(); |
| 14 | |
| 15 | if (typeof promise !== "object" || typeof promise.then !== "function") { |
| 16 | throw new MjsUnitAssertionError( |
| 17 | "Expected " + run.toString() + |
| 18 | " to return a Promise, but it returned " + PrettyPrint(promise)); |
| 19 | } |
| 20 | |
| 21 | promise.then(function(value) { hadValue = true; actual = value; }, |
| 22 | function(error) { hadError = true; actual = error; }); |
| 23 | |
| 24 | assertFalse(hadValue || hadError); |
| 25 | |
| 26 | %PerformMicrotaskCheckpoint(); |
| 27 | |
| 28 | if (!hadError) { |
| 29 | throw new MjsUnitAssertionError( |
| 30 | "Expected " + run + "() to throw " + errorType.name + |
| 31 | ", but did not throw."); |
| 32 | } |
| 33 | if (!(actual instanceof errorType)) |
| 34 | throw new MjsUnitAssertionError( |
| 35 | "Expected " + run + "() to throw " + errorType.name + |
| 36 | ", but threw '" + actual + "'"); |
| 37 | if (message !== void 0 && actual.message !== message) |
| 38 | throw new MjsUnitAssertionError( |
| 39 | "Expected " + run + "() to throw '" + message + "', but threw '" + |
| 40 | actual.message + "'"); |
| 41 | }; |
| 42 | |
| 43 | function assertEqualsAsync(expected, run, msg) { |
| 44 | var actual; |
no test coverage detected