From 29ed098a0bdaea31f3dbe60bb7baa65575221dc5 Mon Sep 17 00:00:00 2001 From: Stafford Williams Date: Mon, 9 Jan 2023 00:13:36 +1100 Subject: [PATCH 1/3] [jest] type done callback on each --- types/jest/index.d.ts | 6 +++--- types/jest/jest-tests.ts | 20 +++++++++++++++++--- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/types/jest/index.d.ts b/types/jest/index.d.ts index aa868b5b7df776..93f5a7847eb4c1 100644 --- a/types/jest/index.d.ts +++ b/types/jest/index.d.ts @@ -494,7 +494,7 @@ declare namespace jest { // Exclusively arrays. (cases: ReadonlyArray): ( name: string, - fn: (...args: T) => any, + fn: (...t: [...args: T, done: DoneCallback]) => any, timeout?: number, ) => void; >(cases: ReadonlyArray): ( @@ -503,7 +503,7 @@ declare namespace jest { timeout?: number, ) => void; // Not arrays. - (cases: ReadonlyArray): (name: string, fn: (...args: T[]) => any, timeout?: number) => void; + (cases: ReadonlyArray): (name: string, fn: (arg: T, done: DoneCallback) => any, timeout?: number) => void; (cases: ReadonlyArray>): ( name: string, fn: (...args: any[]) => any, @@ -511,7 +511,7 @@ declare namespace jest { ) => void; (strings: TemplateStringsArray, ...placeholders: any[]): ( name: string, - fn: (arg: any) => any, + fn: (arg: any, done: DoneCallback) => any, timeout?: number, ) => void; } diff --git a/types/jest/jest-tests.ts b/types/jest/jest-tests.ts index e49c467a1eba9d..8886a25f74981c 100644 --- a/types/jest/jest-tests.ts +++ b/types/jest/jest-tests.ts @@ -1646,12 +1646,24 @@ describe.each([ [1, 1, 2], [1, 2, 3], [2, 1, 3], -])('.add(%i, %i)', (a: number, b: number, expected: number) => { +])('.add(%i, %i)', (a: number, b: number, expected: number, done) => { test(`returns ${expected}`, () => { expect(a + b).toBe(expected); + done(); }); }); +// https://github.com/DefinitelyTyped/DefinitelyTyped/issues/34617 + +it.each([1, 2, 3])('dummy: %d', (num, done) => { + done(); +}); + +const casesReadonlyArray = [[1, 2, 3] as ReadonlyArray] as ReadonlyArray>; +it.each(casesReadonlyArray)('%d', (a, b, c) => { + expect(a + b).toBe(c); +}); + interface Case { a: number; b: number; @@ -1663,9 +1675,10 @@ describe.each` ${1} | ${1} | ${2} ${1} | ${2} | ${3} ${2} | ${1} | ${3} -`('$a + $b', ({ a, b, expected }: Case) => { +`('$a + $b', ({ a, b, expected }: Case, done) => { test(`returns ${expected}`, () => { expect(a + b).toBe(expected); + done(); }); }); @@ -1774,9 +1787,10 @@ test.each` test.each([ [1, '1'], [2, '2'], -])('', (a, b) => { +])('', (a, b, done) => { a; // $ExpectType number b; // $ExpectType string + done; // $ExpectType DoneCallback }); test.only.each([ From 4fda3d2baa4cbb1ca30d02b05ea440122b5f3f2c Mon Sep 17 00:00:00 2001 From: Stafford Williams Date: Wed, 22 Feb 2023 22:14:45 +1100 Subject: [PATCH 2/3] additional test case --- types/jest/jest-tests.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/types/jest/jest-tests.ts b/types/jest/jest-tests.ts index 8886a25f74981c..e3a469ad41df6e 100644 --- a/types/jest/jest-tests.ts +++ b/types/jest/jest-tests.ts @@ -1744,6 +1744,16 @@ test.each([ 5000, ); +test.each([ + [ + { prop1: true, prop2: true }, + { prop1: true, prop2: true }, + ], + [{ prop1: true }, { prop1: true, prop2: false }], +])('%j -> %j', (input, output) => { + console.log(input, output); +}); + declare const constCases: [['a', 'b', 'ab'], ['d', 2, 'd2']]; test.each(constCases)('%s + %s', (...args) => { // following assertion is skipped because of flaky testing From 8fa31a2aa6603a68dd6dfbff5a5fe6a0d4a6e6f8 Mon Sep 17 00:00:00 2001 From: Stafford Williams Date: Wed, 22 Feb 2023 22:15:28 +1100 Subject: [PATCH 3/3] remove typing from array of arrays --- types/jest/index.d.ts | 2 +- types/jest/jest-tests.ts | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/types/jest/index.d.ts b/types/jest/index.d.ts index 93f5a7847eb4c1..9047b1305567a5 100644 --- a/types/jest/index.d.ts +++ b/types/jest/index.d.ts @@ -494,7 +494,7 @@ declare namespace jest { // Exclusively arrays. (cases: ReadonlyArray): ( name: string, - fn: (...t: [...args: T, done: DoneCallback]) => any, + fn: (...args: T) => any, timeout?: number, ) => void; >(cases: ReadonlyArray): ( diff --git a/types/jest/jest-tests.ts b/types/jest/jest-tests.ts index e3a469ad41df6e..064a833a272399 100644 --- a/types/jest/jest-tests.ts +++ b/types/jest/jest-tests.ts @@ -1646,10 +1646,9 @@ describe.each([ [1, 1, 2], [1, 2, 3], [2, 1, 3], -])('.add(%i, %i)', (a: number, b: number, expected: number, done) => { +])('.add(%i, %i)', (a: number, b: number, expected: number) => { test(`returns ${expected}`, () => { expect(a + b).toBe(expected); - done(); }); }); @@ -1797,10 +1796,9 @@ test.each` test.each([ [1, '1'], [2, '2'], -])('', (a, b, done) => { +])('', (a, b) => { a; // $ExpectType number b; // $ExpectType string - done; // $ExpectType DoneCallback }); test.only.each([