From 79010384587f1c3474407ce72500cdbcc18e9792 Mon Sep 17 00:00:00 2001 From: Nayeem Rahman Date: Fri, 15 Nov 2019 03:22:33 +0000 Subject: fix: error handling in std/fs/walk() (#3318) - Make assertThrows() return the Error - Remove WalkOptions::onError() --- std/testing/asserts.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'std/testing') 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 { +): Promise { 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. */ -- cgit v1.2.3