mirror of
https://github.com/denoland/deno.git
synced 2025-02-01 20:25:12 -05:00
Improve empty test case error messages (#3514)
This commit is contained in:
parent
bb24fb74ff
commit
ff6b514a7b
2 changed files with 50 additions and 5 deletions
|
@ -10,6 +10,7 @@ import {
|
||||||
yellow,
|
yellow,
|
||||||
italic
|
italic
|
||||||
} from "../fmt/colors.ts";
|
} from "../fmt/colors.ts";
|
||||||
|
import { assert } from "./asserts.ts";
|
||||||
export type TestFunction = () => void | Promise<void>;
|
export type TestFunction = () => void | Promise<void>;
|
||||||
|
|
||||||
export interface TestDefinition {
|
export interface TestDefinition {
|
||||||
|
@ -121,14 +122,28 @@ export function test(
|
||||||
throw new Error("Missing test function");
|
throw new Error("Missing test function");
|
||||||
}
|
}
|
||||||
name = t;
|
name = t;
|
||||||
} else {
|
if (!name) {
|
||||||
fn = typeof t === "function" ? t : t.fn;
|
throw new Error("The name of test case can't be empty");
|
||||||
|
}
|
||||||
|
} else if (typeof t === "function") {
|
||||||
|
fn = t;
|
||||||
name = t.name;
|
name = t.name;
|
||||||
|
if (!name) {
|
||||||
|
throw new Error("Test function can't be anonymous");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
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)) {
|
if (filter(name)) {
|
||||||
candidates.push({ fn, name });
|
candidates.push({ fn, name });
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -260,4 +260,34 @@ test("test fn overloading", (): void => {
|
||||||
assert(true);
|
assert(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("The name of test case can't be empty", () => {
|
||||||
|
assertThrows(
|
||||||
|
() => {
|
||||||
|
test("", () => {});
|
||||||
|
},
|
||||||
|
Error,
|
||||||
|
"The name of test case can't be empty"
|
||||||
|
);
|
||||||
|
assertThrows(
|
||||||
|
() => {
|
||||||
|
test({
|
||||||
|
name: "",
|
||||||
|
fn: () => {}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
Error,
|
||||||
|
"The name of test case can't be empty"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("test function can't be anonymous", () => {
|
||||||
|
assertThrows(
|
||||||
|
() => {
|
||||||
|
test(function() {});
|
||||||
|
},
|
||||||
|
Error,
|
||||||
|
"Test function can't be anonymous"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
runIfMain(import.meta);
|
runIfMain(import.meta);
|
||||||
|
|
Loading…
Add table
Reference in a new issue