diff --git a/CHANGELOG.md b/CHANGELOG.md index eccb30f33648..92ba35679346 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - `[@jest/expect-utils]` `toMatchObject` diffs should include `Symbol` properties ([#13810](https://github.com/facebook/jest/pull/13810)) - `[jest-runtime]` Handle missing `replaceProperty` ([#13823](https://github.com/facebook/jest/pull/13823)) +- `[@jest/types]` Add partial support for `done` callbacks in typings of `each` ([#13756](https://github.com/facebook/jest/pull/13756)) ### Chore & Maintenance diff --git a/packages/babel-jest/src/__tests__/index.ts b/packages/babel-jest/src/__tests__/index.ts index e0bda219a20e..189d6609a7cc 100644 --- a/packages/babel-jest/src/__tests__/index.ts +++ b/packages/babel-jest/src/__tests__/index.ts @@ -107,38 +107,20 @@ test('Returns source string with inline maps when no transformOptions is passed describe('caller option correctly merges from defaults and options', () => { test.each([ [ - { - supportsDynamicImport: true, - supportsStaticESM: true, - }, - { - supportsDynamicImport: true, - supportsStaticESM: true, - }, + {supportsDynamicImport: true, supportsStaticESM: true}, + {supportsDynamicImport: true, supportsStaticESM: true}, ], [ - { - supportsDynamicImport: false, - supportsStaticESM: false, - }, - { - supportsDynamicImport: false, - supportsStaticESM: false, - }, + {supportsDynamicImport: false, supportsStaticESM: false}, + {supportsDynamicImport: false, supportsStaticESM: false}, ], [ {supportsStaticESM: false}, - { - supportsDynamicImport: false, - supportsStaticESM: false, - }, + {supportsDynamicImport: false, supportsStaticESM: false}, ], [ {supportsDynamicImport: true}, - { - supportsDynamicImport: true, - supportsStaticESM: false, - }, + {supportsDynamicImport: true, supportsStaticESM: false}, ], ])('%j -> %j', (input, output) => { defaultBabelJestTransformer.process(sourceString, 'dummy_path.js', { diff --git a/packages/jest-circus/src/__tests__/hooksError.test.ts b/packages/jest-circus/src/__tests__/hooksError.test.ts index a7a08414d43e..08c135ffe03f 100644 --- a/packages/jest-circus/src/__tests__/hooksError.test.ts +++ b/packages/jest-circus/src/__tests__/hooksError.test.ts @@ -10,16 +10,7 @@ import circus from '../'; describe.each(['beforeEach', 'beforeAll', 'afterEach', 'afterAll'] as const)( '%s hooks error throwing', fn => { - test.each([ - ['String'], - [1], - [[]], - [{}], - [Symbol('hello')], - [true], - [null], - [undefined], - ])( + test.each(['String', 1, [], {}, Symbol('hello'), true, null, undefined])( `${fn} throws an error when %p is provided as a first argument to it`, el => { expect(() => { diff --git a/packages/jest-types/__typetests__/each.test.ts b/packages/jest-types/__typetests__/each.test.ts index 3c9212ca5ed4..cc3965cd3e96 100644 --- a/packages/jest-types/__typetests__/each.test.ts +++ b/packages/jest-types/__typetests__/each.test.ts @@ -28,19 +28,27 @@ const objectTable = [ // test.each expectType( - test.each(list)('some test', a => { + test.each(list)('some test', (a, done) => { expectType(a); + + expectType<(reason?: string | Error) => void>(done); }), ); expectType( - test.each(list)('some test', a => { - expectType(a); - }), + test.each(list)( + 'some test', + a => { + expectType(a); + }, + 1000, + ), ); expectType( - test.each(tupleList)('some test', b => { + test.each(tupleList)('some test', (b, done) => { expectType<'one' | 'two' | 'three'>(b); + + expectType<(reason?: string | Error) => void>(done); }), ); expectType( @@ -54,8 +62,10 @@ expectType( ); expectType( - test.each([3, 4, 'seven'])('some test', c => { + test.each([3, 4, 'seven'])('some test', (c, done) => { expectType(c); + + expectType<(reason?: string | Error) => void>(done); }), ); expectType( @@ -134,11 +144,13 @@ expectType( ); expectType( - test.each(objectTable)('some test', ({a, b, expected, extra}) => { + test.each(objectTable)('some test', ({a, b, expected, extra}, done) => { expectType(a); expectType(b); expectType(expected); expectType(extra); + + expectType<(reason?: string | Error) => void>(done); }), ); expectType( @@ -148,11 +160,13 @@ expectType( {a: 5, b: 6, expected: 'eleven'}, ])( 'some test', - ({a, b, expected, extra}) => { + ({a, b, expected, extra}, done) => { expectType(a); expectType(b); expectType(expected); expectType(extra); + + expectType<(reason?: string | Error) => void>(done); }, 1000, ), @@ -164,10 +178,12 @@ expectType( ${1} | ${1} | ${2} ${1} | ${2} | ${3} ${2} | ${1} | ${3} - `('some test', ({a, b, expected}) => { + `('some test', ({a, b, expected}, done) => { expectType(a); expectType(b); expectType(expected); + + expectType<(reason?: string | Error) => void>(done); }), ); expectType( @@ -185,9 +201,11 @@ expectType( item | expected ${'a'} | ${true} ${'b'} | ${false} - `('some test', ({item, expected}) => { + `('some test', ({item, expected}, done) => { expectType(item); expectType(expected); + + expectType<(reason?: string | Error) => void>(done); }), ); expectType( diff --git a/packages/jest-types/src/Global.ts b/packages/jest-types/src/Global.ts index 6a1bbecb235a..87b9449be23b 100644 --- a/packages/jest-types/src/Global.ts +++ b/packages/jest-types/src/Global.ts @@ -59,7 +59,7 @@ interface Each { // when the table is an array of object literals >(table: ReadonlyArray): ( name: string | NameLike, - fn: (arg: T) => ReturnType, + fn: (arg: T, done: DoneFn) => ReturnType, timeout?: number, ) => void; @@ -80,14 +80,14 @@ interface Each { // when the table is a tuple or array (table: ReadonlyArray): ( name: string | NameLike, - fn: (arg: T) => ReturnType, + fn: (arg: T, done: DoneFn) => ReturnType, timeout?: number, ) => void; // when the table is a template literal (strings: TemplateStringsArray, ...expressions: Array): ( name: string | NameLike, - fn: (arg: Record) => ReturnType, + fn: (arg: Record, done: DoneFn) => ReturnType, timeout?: number, ) => void; @@ -97,7 +97,7 @@ interface Each { ...expressions: Array ): ( name: string | NameLike, - fn: (arg: T) => ReturnType, + fn: (arg: T, done: DoneFn) => ReturnType, timeout?: number, ) => void; }