| Index: test/mjsunit/mjsunit.js
|
| diff --git a/test/mjsunit/mjsunit.js b/test/mjsunit/mjsunit.js
|
| index 9b07953c8aa22a24cd1386e1f212027dab0c7e2f..d80feebd54217e50ac76300659a7f22f22649a38 100644
|
| --- a/test/mjsunit/mjsunit.js
|
| +++ b/test/mjsunit/mjsunit.js
|
| @@ -54,6 +54,7 @@ var assertSame;
|
| // and the properties of non-Array objects).
|
| var assertEquals;
|
|
|
| +var assertEqualsAsync;
|
|
|
| // The difference between expected and found value is within certain tolerance.
|
| var assertEqualsDelta;
|
| @@ -93,6 +94,8 @@ var assertNotNull;
|
| // to the type property on the thrown exception.
|
| var assertThrows;
|
|
|
| +var assertThrowsAsync;
|
| +
|
| // Assert that the passed function throws an exception.
|
| // The exception is checked against the second argument using assertEquals.
|
| var assertThrowsEquals;
|
| @@ -283,6 +286,33 @@ var assertUnoptimized;
|
| };
|
|
|
|
|
| + assertEqualsAsync = function assertEqualsAsync(expected, run, msg) {
|
| + var actual;
|
| + var hadValue = false;
|
| + var hadError = false;
|
| + var promise = run();
|
| +
|
| + if (typeof promise !== "object" || typeof promise.then !== "function") {
|
| + throw new MjsUnitAssertionError(
|
| + "Expected " + run.toString() +
|
| + " to return a Promise, but it returned " + PrettyPrint(promise));
|
| + }
|
| +
|
| + promise.then(function(value) { hadValue = true; actual = value; },
|
| + function(error) { hadError = true; actual = error; });
|
| +
|
| + assertFalse(hadValue || hadError);
|
| +
|
| + flushMicrotasks();
|
| +
|
| + if (hadError) throw actual;
|
| +
|
| + assertTrue(
|
| + hadValue, "Expected '" + run.toString() + "' to produce a value");
|
| +
|
| + assertEquals(expected, actual, msg);
|
| + };
|
| +
|
| assertEqualsDelta =
|
| function assertEqualsDelta(expected, found, delta, name_opt) {
|
| assertTrue(Math.abs(expected - found) <= delta, name_opt);
|
| @@ -369,6 +399,40 @@ var assertUnoptimized;
|
| throw new MjsUnitAssertionError("Did not throw exception");
|
| };
|
|
|
| + assertThrowsAsync = function assertThrowsAsync(run, errorType, message) {
|
| + var actual;
|
| + var hadValue = false;
|
| + var hadError = false;
|
| + var promise = run();
|
| +
|
| + if (typeof promise !== "object" || typeof promise.then !== "function") {
|
| + throw new MjsUnitAssertionError(
|
| + "Expected " + run.toString() +
|
| + " to return a Promise, but it returned " + PrettyPrint(promise));
|
| + }
|
| +
|
| + promise.then(function(value) { hadValue = true; actual = value; },
|
| + function(error) { hadError = true; actual = error; });
|
| +
|
| + assertFalse(hadValue || hadError);
|
| +
|
| + flushMicrotasks();
|
| +
|
| + if (!hadError) {
|
| + throw new MjsUnitAssertionError(
|
| + "Expected " + run + "() to throw " + errorType.name +
|
| + ", but did not throw.");
|
| + }
|
| + if (!(actual instanceof errorType))
|
| + throw new MjsUnitAssertionError(
|
| + "Expected " + run + "() to throw " + errorType.name +
|
| + ", but threw '" + actual + "'");
|
| + if (message !== void 0 && actual.message !== message)
|
| + throw new MjsUnitAssertionError(
|
| + "Expected " + run + "() to throw '" + message + "', but threw '" +
|
| + actual.message + "'");
|
| + };
|
| +
|
|
|
| assertThrowsEquals = function assertThrowsEquals(fun, val) {
|
| try {
|
|
|