Skip to content

Commit 8884105

Browse files
authored
fix(@jest/types): add partial support for done callbacks in typings of each (#13756)
1 parent fbf0fa8 commit 8884105

File tree

5 files changed

+40
-48
lines changed

5 files changed

+40
-48
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
- `[@jest/expect-utils]` `toMatchObject` diffs should include `Symbol` properties ([#13810](https://github.com/facebook/jest/pull/13810))
1111
- `[jest-runtime]` Handle missing `replaceProperty` ([#13823](https://github.com/facebook/jest/pull/13823))
12+
- `[@jest/types]` Add partial support for `done` callbacks in typings of `each` ([#13756](https://github.com/facebook/jest/pull/13756))
1213

1314
### Chore & Maintenance
1415

packages/babel-jest/src/__tests__/index.ts

+6-24
Original file line numberDiff line numberDiff line change
@@ -107,38 +107,20 @@ test('Returns source string with inline maps when no transformOptions is passed
107107
describe('caller option correctly merges from defaults and options', () => {
108108
test.each([
109109
[
110-
{
111-
supportsDynamicImport: true,
112-
supportsStaticESM: true,
113-
},
114-
{
115-
supportsDynamicImport: true,
116-
supportsStaticESM: true,
117-
},
110+
{supportsDynamicImport: true, supportsStaticESM: true},
111+
{supportsDynamicImport: true, supportsStaticESM: true},
118112
],
119113
[
120-
{
121-
supportsDynamicImport: false,
122-
supportsStaticESM: false,
123-
},
124-
{
125-
supportsDynamicImport: false,
126-
supportsStaticESM: false,
127-
},
114+
{supportsDynamicImport: false, supportsStaticESM: false},
115+
{supportsDynamicImport: false, supportsStaticESM: false},
128116
],
129117
[
130118
{supportsStaticESM: false},
131-
{
132-
supportsDynamicImport: false,
133-
supportsStaticESM: false,
134-
},
119+
{supportsDynamicImport: false, supportsStaticESM: false},
135120
],
136121
[
137122
{supportsDynamicImport: true},
138-
{
139-
supportsDynamicImport: true,
140-
supportsStaticESM: false,
141-
},
123+
{supportsDynamicImport: true, supportsStaticESM: false},
142124
],
143125
])('%j -> %j', (input, output) => {
144126
defaultBabelJestTransformer.process(sourceString, 'dummy_path.js', {

packages/jest-circus/src/__tests__/hooksError.test.ts

+1-10
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,7 @@ import circus from '../';
1010
describe.each(['beforeEach', 'beforeAll', 'afterEach', 'afterAll'] as const)(
1111
'%s hooks error throwing',
1212
fn => {
13-
test.each([
14-
['String'],
15-
[1],
16-
[[]],
17-
[{}],
18-
[Symbol('hello')],
19-
[true],
20-
[null],
21-
[undefined],
22-
])(
13+
test.each(['String', 1, [], {}, Symbol('hello'), true, null, undefined])(
2314
`${fn} throws an error when %p is provided as a first argument to it`,
2415
el => {
2516
expect(() => {

packages/jest-types/__typetests__/each.test.ts

+28-10
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,27 @@ const objectTable = [
2828
// test.each
2929

3030
expectType<void>(
31-
test.each(list)('some test', a => {
31+
test.each(list)('some test', (a, done) => {
3232
expectType<number>(a);
33+
34+
expectType<(reason?: string | Error) => void>(done);
3335
}),
3436
);
3537
expectType<void>(
36-
test.each(list)('some test', a => {
37-
expectType<number>(a);
38-
}),
38+
test.each(list)(
39+
'some test',
40+
a => {
41+
expectType<number>(a);
42+
},
43+
1000,
44+
),
3945
);
4046

4147
expectType<void>(
42-
test.each(tupleList)('some test', b => {
48+
test.each(tupleList)('some test', (b, done) => {
4349
expectType<'one' | 'two' | 'three'>(b);
50+
51+
expectType<(reason?: string | Error) => void>(done);
4452
}),
4553
);
4654
expectType<void>(
@@ -54,8 +62,10 @@ expectType<void>(
5462
);
5563

5664
expectType<void>(
57-
test.each([3, 4, 'seven'])('some test', c => {
65+
test.each([3, 4, 'seven'])('some test', (c, done) => {
5866
expectType<string | number>(c);
67+
68+
expectType<(reason?: string | Error) => void>(done);
5969
}),
6070
);
6171
expectType<void>(
@@ -134,11 +144,13 @@ expectType<void>(
134144
);
135145

136146
expectType<void>(
137-
test.each(objectTable)('some test', ({a, b, expected, extra}) => {
147+
test.each(objectTable)('some test', ({a, b, expected, extra}, done) => {
138148
expectType<number>(a);
139149
expectType<number>(b);
140150
expectType<string>(expected);
141151
expectType<boolean | undefined>(extra);
152+
153+
expectType<(reason?: string | Error) => void>(done);
142154
}),
143155
);
144156
expectType<void>(
@@ -148,11 +160,13 @@ expectType<void>(
148160
{a: 5, b: 6, expected: 'eleven'},
149161
])(
150162
'some test',
151-
({a, b, expected, extra}) => {
163+
({a, b, expected, extra}, done) => {
152164
expectType<number>(a);
153165
expectType<number>(b);
154166
expectType<string>(expected);
155167
expectType<boolean | undefined>(extra);
168+
169+
expectType<(reason?: string | Error) => void>(done);
156170
},
157171
1000,
158172
),
@@ -164,10 +178,12 @@ expectType<void>(
164178
${1} | ${1} | ${2}
165179
${1} | ${2} | ${3}
166180
${2} | ${1} | ${3}
167-
`('some test', ({a, b, expected}) => {
181+
`('some test', ({a, b, expected}, done) => {
168182
expectType<number>(a);
169183
expectType<number>(b);
170184
expectType<number>(expected);
185+
186+
expectType<(reason?: string | Error) => void>(done);
171187
}),
172188
);
173189
expectType<void>(
@@ -185,9 +201,11 @@ expectType<void>(
185201
item | expected
186202
${'a'} | ${true}
187203
${'b'} | ${false}
188-
`('some test', ({item, expected}) => {
204+
`('some test', ({item, expected}, done) => {
189205
expectType<string>(item);
190206
expectType<boolean>(expected);
207+
208+
expectType<(reason?: string | Error) => void>(done);
191209
}),
192210
);
193211
expectType<void>(

packages/jest-types/src/Global.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ interface Each<EachFn extends TestFn | BlockFn> {
5959
// when the table is an array of object literals
6060
<T extends Record<string, unknown>>(table: ReadonlyArray<T>): (
6161
name: string | NameLike,
62-
fn: (arg: T) => ReturnType<EachFn>,
62+
fn: (arg: T, done: DoneFn) => ReturnType<EachFn>,
6363
timeout?: number,
6464
) => void;
6565

@@ -80,14 +80,14 @@ interface Each<EachFn extends TestFn | BlockFn> {
8080
// when the table is a tuple or array
8181
<T>(table: ReadonlyArray<T>): (
8282
name: string | NameLike,
83-
fn: (arg: T) => ReturnType<EachFn>,
83+
fn: (arg: T, done: DoneFn) => ReturnType<EachFn>,
8484
timeout?: number,
8585
) => void;
8686

8787
// when the table is a template literal
8888
<T = unknown>(strings: TemplateStringsArray, ...expressions: Array<T>): (
8989
name: string | NameLike,
90-
fn: (arg: Record<string, T>) => ReturnType<EachFn>,
90+
fn: (arg: Record<string, T>, done: DoneFn) => ReturnType<EachFn>,
9191
timeout?: number,
9292
) => void;
9393

@@ -97,7 +97,7 @@ interface Each<EachFn extends TestFn | BlockFn> {
9797
...expressions: Array<unknown>
9898
): (
9999
name: string | NameLike,
100-
fn: (arg: T) => ReturnType<EachFn>,
100+
fn: (arg: T, done: DoneFn) => ReturnType<EachFn>,
101101
timeout?: number,
102102
) => void;
103103
}

0 commit comments

Comments
 (0)