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