Skip to content

Commit

Permalink
feat(std/testing): Allow non-void promises in assertThrowsAsync (#6052)
Browse files Browse the repository at this point in the history
  • Loading branch information
JonShort authored Jun 4, 2020
1 parent e3cc3db commit 4b1638d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
8 changes: 4 additions & 4 deletions std/testing/asserts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions std/testing/asserts_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
assertEquals,
assertStrictEq,
assertThrows,
assertThrowsAsync,
AssertionError,
equal,
fail,
Expand Down Expand Up @@ -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[] => [
"",
"",
Expand Down

0 comments on commit 4b1638d

Please sign in to comment.