feat: add overloaded form of unit test declaration (denoland/deno_std#563)

Original: bd146e0188
This commit is contained in:
Bartek Iwańczuk 2019-08-14 22:12:35 +02:00 committed by Ryan Dahl
parent eab0647bd1
commit d928c0ca31
2 changed files with 23 additions and 3 deletions

View file

@ -86,9 +86,24 @@ function filter(name: string): boolean {
} }
} }
export function test(t: TestDefinition | TestFunction): void { export function test(t: TestDefinition): void;
const fn: TestFunction = typeof t === "function" ? t : t.fn; export function test(fn: TestFunction): void;
const name: string = t.name; 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) { if (!name) {
throw new Error("Test function may not be anonymous"); throw new Error("Test function may not be anonymous");

View file

@ -263,4 +263,9 @@ test(async function testingThrowsAsyncMsgNotIncludes(): Promise<void> {
assert(didThrow); assert(didThrow);
}); });
test("test fn overloading", (): void => {
// just verifying that you can use this test definition syntax
assert(true);
});
runIfMain(import.meta); runIfMain(import.meta);