Skip to content

Commit

Permalink
feat(testing): Allow non-void promises in assertThrowsAsync (denoland…
Browse files Browse the repository at this point in the history
  • Loading branch information
JonShort authored Jun 4, 2020
1 parent c14588d commit 4e9bc2a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
8 changes: 4 additions & 4 deletions 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 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 4e9bc2a

Please sign in to comment.