MCPcopy Create free account
hub / github.com/nodejs/node / assertThrowsAsync

Function assertThrowsAsync

deps/v8/test/mjsunit/es8/async-function-try-finally.js:7–39  ·  view source on GitHub ↗
(run, errorType, message)

Source from the content-addressed store, hash-verified

5// Flags: --allow-natives-syntax
6
7function 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
41function assertEqualsAsync(expected, run, msg) {
42 var actual;

Callers 1

Calls 5

runFunction · 0.70
PrettyPrintFunction · 0.50
assertFalseFunction · 0.50
toStringMethod · 0.45
thenMethod · 0.45

Tested by

no test coverage detected