summaryrefslogtreecommitdiff
path: root/std/testing/asserts.ts
diff options
context:
space:
mode:
authorNayeem Rahman <muhammed.9939@gmail.com>2019-11-15 03:22:33 +0000
committerRy Dahl <ry@tinyclouds.org>2019-11-14 22:22:33 -0500
commit79010384587f1c3474407ce72500cdbcc18e9792 (patch)
tree5305c77674c8f6ed6d575293068f919e03e6904d /std/testing/asserts.ts
parent4902a1cacb0348efde9ab342172f2706ac27e837 (diff)
fix: error handling in std/fs/walk() (#3318)
- Make assertThrows() return the Error - Remove WalkOptions::onError()
Diffstat (limited to 'std/testing/asserts.ts')
-rw-r--r--std/testing/asserts.ts10
1 files changed, 8 insertions, 2 deletions
diff --git a/std/testing/asserts.ts b/std/testing/asserts.ts
index 3ae45454c..e52644e7a 100644
--- a/std/testing/asserts.ts
+++ b/std/testing/asserts.ts
@@ -308,8 +308,9 @@ export function assertThrows(
ErrorClass?: Constructor,
msgIncludes = "",
msg?: string
-): void {
+): Error {
let doesThrow = false;
+ let error = null;
try {
fn();
} catch (e) {
@@ -326,11 +327,13 @@ export function assertThrows(
throw new AssertionError(msg);
}
doesThrow = true;
+ error = e;
}
if (!doesThrow) {
msg = `Expected function to throw${msg ? `: ${msg}` : "."}`;
throw new AssertionError(msg);
}
+ return error;
}
export async function assertThrowsAsync(
@@ -338,8 +341,9 @@ export async function assertThrowsAsync(
ErrorClass?: Constructor,
msgIncludes = "",
msg?: string
-): Promise<void> {
+): Promise<Error> {
let doesThrow = false;
+ let error = null;
try {
await fn();
} catch (e) {
@@ -356,11 +360,13 @@ export async function assertThrowsAsync(
throw new AssertionError(msg);
}
doesThrow = true;
+ error = e;
}
if (!doesThrow) {
msg = `Expected function to throw${msg ? `: ${msg}` : "."}`;
throw new AssertionError(msg);
}
+ return error;
}
/** Use this to stub out methods that will throw when invoked. */