summaryrefslogtreecommitdiff
path: root/testing/mod.ts
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2019-08-14 22:12:35 +0200
committerRyan Dahl <ry@tinyclouds.org>2019-08-14 16:12:35 -0400
commitd928c0ca31d6ec8533d5fab5d084ad3708f63ad5 (patch)
tree8e15773027f6e7c0a223ccf9b5b7f8136b63dc27 /testing/mod.ts
parenteab0647bd1184d0ade9a54b8720eb52300d2ba5d (diff)
feat: add overloaded form of unit test declaration (denoland/deno_std#563)
Original: https://github.com/denoland/deno_std/commit/bd146e0188dbd2c4a802e0af6e6b0705675c4abb
Diffstat (limited to 'testing/mod.ts')
-rw-r--r--testing/mod.ts21
1 files changed, 18 insertions, 3 deletions
diff --git a/testing/mod.ts b/testing/mod.ts
index 462c13fb1..fa6fda246 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(fn: TestFunction): void;
+export function test(name: string, fn: 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");