From 643921775e9d3873c851d251c9b0f3c75a30b34a Mon Sep 17 00:00:00 2001 From: Stafford Williams Date: Wed, 15 Mar 2023 16:13:11 +1100 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20Merge=20PR=20#63882=20[jest]=20t?= =?UTF-8?q?ype=20done=20callback=20on=20each=20by=20@staff0rd?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [jest] type done callback on each * additional test case * remove typing from array of arrays --- types/jest/index.d.ts | 4 ++-- types/jest/jest-tests.ts | 24 +++++++++++++++++++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/types/jest/index.d.ts b/types/jest/index.d.ts index dfa7e0c5b06912..77494d56ade121 100644 --- a/types/jest/index.d.ts +++ b/types/jest/index.d.ts @@ -486,7 +486,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, @@ -494,7 +494,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 9a45a362fec1be..4b9861c037bead 100644 --- a/types/jest/jest-tests.ts +++ b/types/jest/jest-tests.ts @@ -1675,6 +1675,17 @@ describe.each([ }); }); +// 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; @@ -1686,9 +1697,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(); }); }); @@ -1754,6 +1766,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) => { // $ExpectType ["a", "b", "ab"] | ["d", 2, "d2"]