Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add overloaded form of unit test declaration #563

Merged
merged 2 commits into from
Aug 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions testing/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
5 changes: 5 additions & 0 deletions testing/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,4 +263,9 @@ test(async function testingThrowsAsyncMsgNotIncludes(): Promise<void> {
assert(didThrow);
});

test("test fn overloading", (): void => {
// just verifying that you can use this test definition syntax
assert(true);
});

runIfMain(import.meta);