aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/bun-types/bun-test.d.ts20
-rw-r--r--packages/bun-types/tests/test.test-d.ts49
2 files changed, 59 insertions, 10 deletions
diff --git a/packages/bun-types/bun-test.d.ts b/packages/bun-types/bun-test.d.ts
index b32ffb4f7..6c22ad62f 100644
--- a/packages/bun-types/bun-test.d.ts
+++ b/packages/bun-types/bun-test.d.ts
@@ -174,18 +174,18 @@ declare module "bun:test" {
*
* @param table Array of Arrays with the arguments that are passed into the test fn for each row.
*/
- each<T extends ReadonlyArray<unknown>>(
- table: ReadonlyArray<T>,
+ each<T extends Readonly<Readonly<[any, ...any[]]>[]>>(
+ table: T,
): (
label: string,
- fn: (...args: T) => void | Promise<unknown>,
+ fn: (...args: Readonly<T>[number]) => void | Promise<unknown>,
options?: number | TestOptions,
) => void;
- each<T>(
+ each<T extends Array<any>>(
table: ReadonlyArray<T>,
): (
label: string,
- fn: (arg: T) => void | Promise<unknown>,
+ fn: (...args: Readonly<T>) => void | Promise<unknown>,
options?: number | TestOptions,
) => void;
};
@@ -419,18 +419,18 @@ declare module "bun:test" {
*
* @param table Array of Arrays with the arguments that are passed into the test fn for each row.
*/
- each<T extends ReadonlyArray<unknown>>(
- table: ReadonlyArray<T>,
+ each<T extends Readonly<Readonly<[any, ...any[]]>[]>>(
+ table: T,
): (
label: string,
- fn: (...args: T) => void | Promise<unknown>,
+ fn: (...args: Readonly<T>[number]) => void | Promise<unknown>,
options?: number | TestOptions,
) => void;
- each<T>(
+ each<T extends Array<any>>(
table: ReadonlyArray<T>,
): (
label: string,
- fn: (arg: T, done: (err?: unknown) => void) => void | Promise<unknown>,
+ fn: (...args: Readonly<T>) => void | Promise<unknown>,
options?: number | TestOptions,
) => void;
};
diff --git a/packages/bun-types/tests/test.test-d.ts b/packages/bun-types/tests/test.test-d.ts
index 831b18e2e..1e67590b2 100644
--- a/packages/bun-types/tests/test.test-d.ts
+++ b/packages/bun-types/tests/test.test-d.ts
@@ -63,3 +63,52 @@ describe("bun:test", () => {
expect(undefined).not.toBeDefined();
});
});
+
+// inference should work when data is passed directly in
+test.each([
+ ["a", true, 5],
+ ["b", false, 1234],
+])("test.each", (a, b, c) => {
+ expectType<string>(a);
+ expectType<boolean>(b);
+ expectType<number | string>(c);
+});
+describe.each([
+ ["a", true, 5],
+ ["b", false, "asdf"],
+])("test.each", (a, b, c) => {
+ expectType<string>(a);
+ expectType<boolean>(b);
+ expectType<number | string>(c);
+});
+
+// no inference on data
+const data = [
+ ["a", true, 5],
+ ["b", false, "asdf"],
+];
+test.each(data)("test.each", (...args) => {
+ expectType<string | number | boolean>(args[0]);
+});
+describe.each(data)("test.each", (a, b, c) => {
+ expectType<string | number | boolean>(a);
+ expectType<string | number | boolean>(b);
+ expectType<string | number | boolean>(c);
+});
+
+// as const
+const dataAsConst = [
+ ["a", true, 5],
+ ["b", false, "asdf"],
+] as const;
+
+test.each(dataAsConst)("test.each", (...args) => {
+ expectType<string>(args[0]);
+ expectType<boolean>(args[1]);
+ expectType<string | number>(args[2]);
+});
+describe.each(dataAsConst)("test.each", (...args) => {
+ expectType<string>(args[0]);
+ expectType<boolean>(args[1]);
+ expectType<string | number>(args[2]);
+});