Skip to content

Commit 6eeddb3

Browse files
authored
fix(testing): cause type error for async function as describe body (denoland#5355)
1 parent 0d668fa commit 6eeddb3

File tree

3 files changed

+46
-11
lines changed

3 files changed

+46
-11
lines changed

testing/_test_suite.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/** The options for creating a test suite with the describe function. */
33
export interface DescribeDefinition<T> extends Omit<Deno.TestDefinition, "fn"> {
44
/** The body of the test suite */
5-
fn?: () => void;
5+
fn?: () => void | undefined;
66
/**
77
* The `describe` function returns a `TestSuite` representing the group of tests.
88
* If `describe` is called within another `describe` calls `fn`, the suite will default to that parent `describe` calls returned `TestSuite`.

testing/bdd.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -915,20 +915,20 @@ export type DescribeArgs<T> =
915915
name: string,
916916
options: Omit<DescribeDefinition<T>, "name">,
917917
]
918-
| [name: string, fn: () => void]
919-
| [fn: () => void]
918+
| [name: string, fn: () => void | undefined]
919+
| [fn: () => void | undefined]
920920
| [
921921
name: string,
922922
options: Omit<DescribeDefinition<T>, "fn" | "name">,
923-
fn: () => void,
923+
fn: () => void | undefined,
924924
]
925925
| [
926926
options: Omit<DescribeDefinition<T>, "fn">,
927-
fn: () => void,
927+
fn: () => void | undefined,
928928
]
929929
| [
930930
options: Omit<DescribeDefinition<T>, "fn" | "name">,
931-
fn: () => void,
931+
fn: () => void | undefined,
932932
]
933933
| [
934934
suite: TestSuite<T>,
@@ -942,27 +942,27 @@ export type DescribeArgs<T> =
942942
| [
943943
suite: TestSuite<T>,
944944
name: string,
945-
fn: () => void,
945+
fn: () => void | undefined,
946946
]
947947
| [
948948
suite: TestSuite<T>,
949-
fn: () => void,
949+
fn: () => void | undefined,
950950
]
951951
| [
952952
suite: TestSuite<T>,
953953
name: string,
954954
options: Omit<DescribeDefinition<T>, "fn" | "name" | "suite">,
955-
fn: () => void,
955+
fn: () => void | undefined,
956956
]
957957
| [
958958
suite: TestSuite<T>,
959959
options: Omit<DescribeDefinition<T>, "fn" | "suite">,
960-
fn: () => void,
960+
fn: () => void | undefined,
961961
]
962962
| [
963963
suite: TestSuite<T>,
964964
options: Omit<DescribeDefinition<T>, "fn" | "name" | "suite">,
965-
fn: () => void,
965+
fn: () => void | undefined,
966966
];
967967

968968
/** Generates a DescribeDefinition from DescribeArgs. */

testing/bdd_test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2008,4 +2008,39 @@ Deno.test("describe()", async (t) => {
20082008
}
20092009
},
20102010
);
2011+
2012+
await t.step(
2013+
"cause type error if async function is passed as describe definition",
2014+
() => {
2015+
// @ts-expect-error async function is not assignable to describe argument
2016+
describe({ name: "example", fn: async () => {} });
2017+
// @ts-expect-error async function is not assignable to describe argument
2018+
describe("example", { fn: async () => {} });
2019+
// @ts-expect-error async function is not assignable to describe argument
2020+
describe("example", async () => {});
2021+
// TODO(kt3k): This case should be type error but it's checked as
2022+
// DescribeDefinition<T> and passes the type check
2023+
// describe(async function example() {});
2024+
// @ts-expect-error async function is not assignable to describe argument
2025+
describe("example", {}, async () => {});
2026+
// @ts-expect-error async function is not assignable to describe argument
2027+
describe({ name: "example" }, async () => {});
2028+
// @ts-expect-error async function is not assignable to describe argument
2029+
describe({}, async function example() {});
2030+
2031+
const suite = describe("example");
2032+
// @ts-expect-error async function is not assignable to describe argument
2033+
describe(suite, "example", { fn: async () => {} });
2034+
// @ts-expect-error async function is not assignable to describe argument
2035+
describe(suite, "example", async () => {});
2036+
// @ts-expect-error async function is not assignable to describe argument
2037+
describe(suite, async () => {});
2038+
// @ts-expect-error async function is not assignable to describe argument
2039+
describe(suite, "example", {}, async () => {});
2040+
// @ts-expect-error async function is not assignable to describe argument
2041+
describe(suite, { name: "example" }, async () => {});
2042+
// @ts-expect-error async function is not assignable to describe argument
2043+
describe(suite, {}, async function example() {});
2044+
},
2045+
);
20112046
});

0 commit comments

Comments
 (0)