diff options
author | Jon Short <JonShort@users.noreply.github.com> | 2020-06-04 15:43:05 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-04 10:43:05 -0400 |
commit | 4b1638dccc601ff0282172c7e3ef0f1126a603ed (patch) | |
tree | b6846d0be55adf568febe2cf1f89e173cc25e918 | |
parent | e3cc3db20fc86d9adb19bb472e8c96ae5f7c77c0 (diff) |
feat(std/testing): Allow non-void promises in assertThrowsAsync (#6052)
-rw-r--r-- | std/testing/asserts.ts | 8 | ||||
-rw-r--r-- | std/testing/asserts_test.ts | 15 |
2 files changed, 19 insertions, 4 deletions
diff --git a/std/testing/asserts.ts b/std/testing/asserts.ts index 18cf9134e..5f5c3a7c5 100644 --- a/std/testing/asserts.ts +++ b/std/testing/asserts.ts @@ -325,8 +325,8 @@ export function fail(msg?: string): void { * throws. An error class and a string that should be included in the * error message can also be asserted. */ -export function assertThrows( - fn: () => void, +export function assertThrows<T = void>( + fn: () => T, ErrorClass?: Constructor, msgIncludes = "", msg?: string @@ -361,8 +361,8 @@ export function assertThrows( return error; } -export async function assertThrowsAsync( - fn: () => Promise<void>, +export async function assertThrowsAsync<T = void>( + fn: () => Promise<T>, ErrorClass?: Constructor, msgIncludes = "", msg?: string diff --git a/std/testing/asserts_test.ts b/std/testing/asserts_test.ts index c333d41da..3969cd661 100644 --- a/std/testing/asserts_test.ts +++ b/std/testing/asserts_test.ts @@ -9,6 +9,7 @@ import { assertEquals, assertStrictEq, assertThrows, + assertThrowsAsync, AssertionError, equal, fail, @@ -245,6 +246,20 @@ test("testingAssertFailWithWrongErrorClass", function (): void { ); }); +test("testingAssertThrowsWithReturnType", () => { + assertThrows(() => { + throw new Error(); + return "a string"; + }); +}); + +test("testingAssertThrowsAsyncWithReturnType", () => { + assertThrowsAsync(() => { + throw new Error(); + return Promise.resolve("a Promise<string>"); + }); +}); + const createHeader = (): string[] => [ "", "", |