From 10918adf3b8dca2436ae5944f746e1248eb3155e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Wed, 14 Aug 2019 20:44:00 +0200 Subject: [PATCH 1/2] add overloaded form of unit test declaration --- testing/mod.ts | 21 ++++++++++++++++++--- testing/test.ts | 5 +++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/testing/mod.ts b/testing/mod.ts index 462c13fb1691..b4e7b5f86b8e 100644 --- a/testing/mod.ts +++ b/testing/mod.ts @@ -86,9 +86,24 @@ function filter(name: string): boolean { } } -export function test(t: TestDefinition | TestFunction): void { - const fn: TestFunction = typeof t === "function" ? t : t.fn; - const name: string = t.name; +export function test(t: TestDefinition): void; +export function test(t: TestFunction): void; +export function test(name: string, t: TestFunction): void; +export function test( + t: string | TestDefinition | TestFunction, + fn?: TestFunction +): void { + let name: string; + + if (typeof t === "string") { + if (!fn) { + throw new Error("Missing test function"); + } + name = t; + } else { + fn = typeof t === "function" ? t : t.fn; + name = t.name; + } if (!name) { throw new Error("Test function may not be anonymous"); diff --git a/testing/test.ts b/testing/test.ts index 8c86791bab6d..171655a9064c 100644 --- a/testing/test.ts +++ b/testing/test.ts @@ -263,4 +263,9 @@ test(async function testingThrowsAsyncMsgNotIncludes(): Promise { assert(didThrow); }); +test("test fn overloading", () => { + // just verifying that you can use this test definition syntax + assert(true); +}); + runIfMain(import.meta); From 0a94c7078071ae86117dba50b72a67f35c89f079 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Wed, 14 Aug 2019 20:49:49 +0200 Subject: [PATCH 2/2] lint --- testing/mod.ts | 4 ++-- testing/test.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/testing/mod.ts b/testing/mod.ts index b4e7b5f86b8e..fa6fda246dc3 100644 --- a/testing/mod.ts +++ b/testing/mod.ts @@ -87,8 +87,8 @@ function filter(name: string): boolean { } export function test(t: TestDefinition): void; -export function test(t: TestFunction): void; -export function test(name: string, t: TestFunction): void; +export function test(fn: TestFunction): void; +export function test(name: string, fn: TestFunction): void; export function test( t: string | TestDefinition | TestFunction, fn?: TestFunction diff --git a/testing/test.ts b/testing/test.ts index 171655a9064c..3a35be1e9893 100644 --- a/testing/test.ts +++ b/testing/test.ts @@ -263,7 +263,7 @@ test(async function testingThrowsAsyncMsgNotIncludes(): Promise { assert(didThrow); }); -test("test fn overloading", () => { +test("test fn overloading", (): void => { // just verifying that you can use this test definition syntax assert(true); });