diff --git a/types/jest/index.d.ts b/types/jest/index.d.ts index aa868b5b7df776..9047b1305567a5 100644 --- a/types/jest/index.d.ts +++ b/types/jest/index.d.ts @@ -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..064a833a272399 100644 --- a/types/jest/jest-tests.ts +++ b/types/jest/jest-tests.ts @@ -1652,6 +1652,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; @@ -1663,9 +1674,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(); }); }); @@ -1731,6 +1743,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