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

fix(testing): cause type error for async function as describe body #5355

Merged
merged 1 commit into from
Jul 9, 2024
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
2 changes: 1 addition & 1 deletion testing/_test_suite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/** The options for creating a test suite with the describe function. */
export interface DescribeDefinition<T> extends Omit<Deno.TestDefinition, "fn"> {
/** The body of the test suite */
fn?: () => void;
fn?: () => void | undefined;
/**
* The `describe` function returns a `TestSuite` representing the group of tests.
* If `describe` is called within another `describe` calls `fn`, the suite will default to that parent `describe` calls returned `TestSuite`.
Expand Down
20 changes: 10 additions & 10 deletions testing/bdd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -915,20 +915,20 @@ export type DescribeArgs<T> =
name: string,
options: Omit<DescribeDefinition<T>, "name">,
]
| [name: string, fn: () => void]
| [fn: () => void]
| [name: string, fn: () => void | undefined]
| [fn: () => void | undefined]
| [
name: string,
options: Omit<DescribeDefinition<T>, "fn" | "name">,
fn: () => void,
fn: () => void | undefined,
]
| [
options: Omit<DescribeDefinition<T>, "fn">,
fn: () => void,
fn: () => void | undefined,
]
| [
options: Omit<DescribeDefinition<T>, "fn" | "name">,
fn: () => void,
fn: () => void | undefined,
]
| [
suite: TestSuite<T>,
Expand All @@ -942,27 +942,27 @@ export type DescribeArgs<T> =
| [
suite: TestSuite<T>,
name: string,
fn: () => void,
fn: () => void | undefined,
]
| [
suite: TestSuite<T>,
fn: () => void,
fn: () => void | undefined,
]
| [
suite: TestSuite<T>,
name: string,
options: Omit<DescribeDefinition<T>, "fn" | "name" | "suite">,
fn: () => void,
fn: () => void | undefined,
]
| [
suite: TestSuite<T>,
options: Omit<DescribeDefinition<T>, "fn" | "suite">,
fn: () => void,
fn: () => void | undefined,
]
| [
suite: TestSuite<T>,
options: Omit<DescribeDefinition<T>, "fn" | "name" | "suite">,
fn: () => void,
fn: () => void | undefined,
];

/** Generates a DescribeDefinition from DescribeArgs. */
Expand Down
35 changes: 35 additions & 0 deletions testing/bdd_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2008,4 +2008,39 @@ Deno.test("describe()", async (t) => {
}
},
);

await t.step(
"cause type error if async function is passed as describe definition",
() => {
// @ts-expect-error async function is not assignable to describe argument
describe({ name: "example", fn: async () => {} });
// @ts-expect-error async function is not assignable to describe argument
describe("example", { fn: async () => {} });
// @ts-expect-error async function is not assignable to describe argument
describe("example", async () => {});
// TODO(kt3k): This case should be type error but it's checked as
// DescribeDefinition<T> and passes the type check
// describe(async function example() {});
// @ts-expect-error async function is not assignable to describe argument
describe("example", {}, async () => {});
// @ts-expect-error async function is not assignable to describe argument
describe({ name: "example" }, async () => {});
// @ts-expect-error async function is not assignable to describe argument
describe({}, async function example() {});

const suite = describe("example");
// @ts-expect-error async function is not assignable to describe argument
describe(suite, "example", { fn: async () => {} });
// @ts-expect-error async function is not assignable to describe argument
describe(suite, "example", async () => {});
// @ts-expect-error async function is not assignable to describe argument
describe(suite, async () => {});
// @ts-expect-error async function is not assignable to describe argument
describe(suite, "example", {}, async () => {});
// @ts-expect-error async function is not assignable to describe argument
describe(suite, { name: "example" }, async () => {});
// @ts-expect-error async function is not assignable to describe argument
describe(suite, {}, async function example() {});
},
);
});