From ff6b514a7b1087e7e5f363305cce46b513a3e562 Mon Sep 17 00:00:00 2001 From: Yoshiya Hinosawa Date: Wed, 18 Dec 2019 22:05:58 +0900 Subject: Improve empty test case error messages (#3514) --- std/testing/mod.ts | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'std/testing/mod.ts') diff --git a/std/testing/mod.ts b/std/testing/mod.ts index 3b6386d5b..0d5d2702a 100644 --- a/std/testing/mod.ts +++ b/std/testing/mod.ts @@ -10,6 +10,7 @@ import { yellow, italic } from "../fmt/colors.ts"; +import { assert } from "./asserts.ts"; export type TestFunction = () => void | Promise; export interface TestDefinition { @@ -121,14 +122,28 @@ export function test( throw new Error("Missing test function"); } name = t; + if (!name) { + throw new Error("The name of test case can't be empty"); + } + } else if (typeof t === "function") { + fn = t; + name = t.name; + if (!name) { + throw new Error("Test function can't be anonymous"); + } } else { - fn = typeof t === "function" ? t : t.fn; + fn = t.fn; + if (!fn) { + throw new Error("Missing test function"); + } name = t.name; + if (!name) { + throw new Error("The name of test case can't be empty"); + } } + assert(!!name, "The name of test case shouldn't be empty"); + assert(!!fn, "Test function shouldn't be empty"); - if (!name) { - throw new Error("Test function may not be anonymous"); - } if (filter(name)) { candidates.push({ fn, name }); } else { -- cgit v1.2.3