Skip to content

Commit a39810a

Browse files
committed
fix
1 parent f45b04e commit a39810a

File tree

3 files changed

+107
-110
lines changed

3 files changed

+107
-110
lines changed

e2e/__tests__/__snapshots__/testFailing.test.ts.snap

Lines changed: 75 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -38,49 +38,43 @@ exports[`works with all statuses 1`] = `
3838
3939
Failing test passed even though it was supposed to fail. Remove \`.failing\` to remove error.
4040
41+
28 | });
42+
29 |
43+
> 30 | test.failing.each([
44+
| ^
45+
31 | {a: 1, b: 1, expected: 2},
4146
32 | {a: 1, b: 2, expected: 3},
4247
33 | {a: 2, b: 1, expected: 3},
43-
> 34 | ])('.add($a, $b)', ({a, b, expected}) => {
44-
| ^
45-
35 | expect(a + b).toBe(expected);
46-
36 | });
47-
37 |
4848
49-
at ../../packages/jest-each/build/bind.js:38:11
50-
at Array.forEach (<anonymous>)
51-
at Object.<anonymous> (__tests__/statuses.test.js:34:3)
49+
at Object.each (__tests__/statuses.test.js:30:14)
5250
5351
● .add(1, 2)
5452
5553
Failing test passed even though it was supposed to fail. Remove \`.failing\` to remove error.
5654
55+
28 | });
56+
29 |
57+
> 30 | test.failing.each([
58+
| ^
59+
31 | {a: 1, b: 1, expected: 2},
5760
32 | {a: 1, b: 2, expected: 3},
5861
33 | {a: 2, b: 1, expected: 3},
59-
> 34 | ])('.add($a, $b)', ({a, b, expected}) => {
60-
| ^
61-
35 | expect(a + b).toBe(expected);
62-
36 | });
63-
37 |
6462
65-
at ../../packages/jest-each/build/bind.js:38:11
66-
at Array.forEach (<anonymous>)
67-
at Object.<anonymous> (__tests__/statuses.test.js:34:3)
63+
at Object.each (__tests__/statuses.test.js:30:14)
6864
6965
● .add(2, 1)
7066
7167
Failing test passed even though it was supposed to fail. Remove \`.failing\` to remove error.
7268
69+
28 | });
70+
29 |
71+
> 30 | test.failing.each([
72+
| ^
73+
31 | {a: 1, b: 1, expected: 2},
7374
32 | {a: 1, b: 2, expected: 3},
7475
33 | {a: 2, b: 1, expected: 3},
75-
> 34 | ])('.add($a, $b)', ({a, b, expected}) => {
76-
| ^
77-
35 | expect(a + b).toBe(expected);
78-
36 | });
79-
37 |
8076
81-
at ../../packages/jest-each/build/bind.js:38:11
82-
at Array.forEach (<anonymous>)
83-
at Object.<anonymous> (__tests__/statuses.test.js:34:3)
77+
at Object.each (__tests__/statuses.test.js:30:14)
8478
8579
● failing passes = fails
8680
@@ -127,51 +121,45 @@ exports[`works with concurrent and only mode 1`] = `
127121
128122
Failing test passed even though it was supposed to fail. Remove \`.failing\` to remove error.
129123
124+
15 | });
125+
16 |
126+
> 17 | test.concurrent.only.failing.each([
127+
| ^
128+
18 | {a: 1, b: 1, expected: 2},
130129
19 | {a: 1, b: 2, expected: 3},
131130
20 | {a: 2, b: 1, expected: 3},
132-
> 21 | ])('.add($a, $b)', ({a, b, expected}) => {
133-
| ^
134-
22 | expect(a + b).toBe(expected);
135-
23 | });
136-
24 |
137131
138-
at ../../packages/jest-each/build/bind.js:38:11
139-
at Array.forEach (<anonymous>)
140-
at __tests__/worksWithConcurrentOnlyMode.test.js:21:5
132+
at each (__tests__/worksWithConcurrentOnlyMode.test.js:17:32)
141133
at Object.describe (__tests__/worksWithConcurrentOnlyMode.test.js:8:1)
142134
143135
● block with concurrent › .add(1, 2)
144136
145137
Failing test passed even though it was supposed to fail. Remove \`.failing\` to remove error.
146138
139+
15 | });
140+
16 |
141+
> 17 | test.concurrent.only.failing.each([
142+
| ^
143+
18 | {a: 1, b: 1, expected: 2},
147144
19 | {a: 1, b: 2, expected: 3},
148145
20 | {a: 2, b: 1, expected: 3},
149-
> 21 | ])('.add($a, $b)', ({a, b, expected}) => {
150-
| ^
151-
22 | expect(a + b).toBe(expected);
152-
23 | });
153-
24 |
154146
155-
at ../../packages/jest-each/build/bind.js:38:11
156-
at Array.forEach (<anonymous>)
157-
at __tests__/worksWithConcurrentOnlyMode.test.js:21:5
147+
at each (__tests__/worksWithConcurrentOnlyMode.test.js:17:32)
158148
at Object.describe (__tests__/worksWithConcurrentOnlyMode.test.js:8:1)
159149
160150
● block with concurrent › .add(2, 1)
161151
162152
Failing test passed even though it was supposed to fail. Remove \`.failing\` to remove error.
163153
154+
15 | });
155+
16 |
156+
> 17 | test.concurrent.only.failing.each([
157+
| ^
158+
18 | {a: 1, b: 1, expected: 2},
164159
19 | {a: 1, b: 2, expected: 3},
165160
20 | {a: 2, b: 1, expected: 3},
166-
> 21 | ])('.add($a, $b)', ({a, b, expected}) => {
167-
| ^
168-
22 | expect(a + b).toBe(expected);
169-
23 | });
170-
24 |
171161
172-
at ../../packages/jest-each/build/bind.js:38:11
173-
at Array.forEach (<anonymous>)
174-
at __tests__/worksWithConcurrentOnlyMode.test.js:21:5
162+
at each (__tests__/worksWithConcurrentOnlyMode.test.js:17:32)
175163
at Object.describe (__tests__/worksWithConcurrentOnlyMode.test.js:8:1)"
176164
`;
177165
@@ -222,51 +210,45 @@ exports[`works with concurrent mode 1`] = `
222210
223211
Failing test passed even though it was supposed to fail. Remove \`.failing\` to remove error.
224212
213+
15 | });
214+
16 |
215+
> 17 | test.concurrent.failing.each([
216+
| ^
217+
18 | {a: 1, b: 1, expected: 2},
225218
19 | {a: 1, b: 2, expected: 3},
226219
20 | {a: 2, b: 1, expected: 3},
227-
> 21 | ])('.add($a, $b)', ({a, b, expected}) => {
228-
| ^
229-
22 | expect(a + b).toBe(expected);
230-
23 | });
231-
24 |
232220
233-
at ../../packages/jest-each/build/bind.js:38:11
234-
at Array.forEach (<anonymous>)
235-
at __tests__/worksWithConcurrentMode.test.js:21:5
221+
at each (__tests__/worksWithConcurrentMode.test.js:17:27)
236222
at Object.describe (__tests__/worksWithConcurrentMode.test.js:8:1)
237223
238224
● block with concurrent › .add(1, 2)
239225
240226
Failing test passed even though it was supposed to fail. Remove \`.failing\` to remove error.
241227
228+
15 | });
229+
16 |
230+
> 17 | test.concurrent.failing.each([
231+
| ^
232+
18 | {a: 1, b: 1, expected: 2},
242233
19 | {a: 1, b: 2, expected: 3},
243234
20 | {a: 2, b: 1, expected: 3},
244-
> 21 | ])('.add($a, $b)', ({a, b, expected}) => {
245-
| ^
246-
22 | expect(a + b).toBe(expected);
247-
23 | });
248-
24 |
249235
250-
at ../../packages/jest-each/build/bind.js:38:11
251-
at Array.forEach (<anonymous>)
252-
at __tests__/worksWithConcurrentMode.test.js:21:5
236+
at each (__tests__/worksWithConcurrentMode.test.js:17:27)
253237
at Object.describe (__tests__/worksWithConcurrentMode.test.js:8:1)
254238
255239
● block with concurrent › .add(2, 1)
256240
257241
Failing test passed even though it was supposed to fail. Remove \`.failing\` to remove error.
258242
243+
15 | });
244+
16 |
245+
> 17 | test.concurrent.failing.each([
246+
| ^
247+
18 | {a: 1, b: 1, expected: 2},
259248
19 | {a: 1, b: 2, expected: 3},
260249
20 | {a: 2, b: 1, expected: 3},
261-
> 21 | ])('.add($a, $b)', ({a, b, expected}) => {
262-
| ^
263-
22 | expect(a + b).toBe(expected);
264-
23 | });
265-
24 |
266250
267-
at ../../packages/jest-each/build/bind.js:38:11
268-
at Array.forEach (<anonymous>)
269-
at __tests__/worksWithConcurrentMode.test.js:21:5
251+
at each (__tests__/worksWithConcurrentMode.test.js:17:27)
270252
at Object.describe (__tests__/worksWithConcurrentMode.test.js:8:1)"
271253
`;
272254
@@ -297,51 +279,45 @@ exports[`works with only mode 1`] = `
297279
298280
Failing test passed even though it was supposed to fail. Remove \`.failing\` to remove error.
299281
282+
13 | });
283+
14 |
284+
> 15 | it.only.failing.each([
285+
| ^
286+
16 | {a: 1, b: 1, expected: 2},
300287
17 | {a: 1, b: 2, expected: 3},
301288
18 | {a: 2, b: 1, expected: 3},
302-
> 19 | ])('.add($a, $b)', ({a, b, expected}) => {
303-
| ^
304-
20 | expect(a + b).toBe(expected);
305-
21 | });
306-
22 |
307-
308-
at ../../packages/jest-each/build/bind.js:38:11
309-
at Array.forEach (<anonymous>)
310-
at __tests__/worksWithOnlyMode.test.js:19:5
289+
290+
at each (__tests__/worksWithOnlyMode.test.js:15:19)
311291
at Object.describe (__tests__/worksWithOnlyMode.test.js:10:1)
312292
313293
● block with only, should pass › .add(1, 2)
314294
315295
Failing test passed even though it was supposed to fail. Remove \`.failing\` to remove error.
316296
297+
13 | });
298+
14 |
299+
> 15 | it.only.failing.each([
300+
| ^
301+
16 | {a: 1, b: 1, expected: 2},
317302
17 | {a: 1, b: 2, expected: 3},
318303
18 | {a: 2, b: 1, expected: 3},
319-
> 19 | ])('.add($a, $b)', ({a, b, expected}) => {
320-
| ^
321-
20 | expect(a + b).toBe(expected);
322-
21 | });
323-
22 |
324-
325-
at ../../packages/jest-each/build/bind.js:38:11
326-
at Array.forEach (<anonymous>)
327-
at __tests__/worksWithOnlyMode.test.js:19:5
304+
305+
at each (__tests__/worksWithOnlyMode.test.js:15:19)
328306
at Object.describe (__tests__/worksWithOnlyMode.test.js:10:1)
329307
330308
● block with only, should pass › .add(2, 1)
331309
332310
Failing test passed even though it was supposed to fail. Remove \`.failing\` to remove error.
333311
312+
13 | });
313+
14 |
314+
> 15 | it.only.failing.each([
315+
| ^
316+
16 | {a: 1, b: 1, expected: 2},
334317
17 | {a: 1, b: 2, expected: 3},
335318
18 | {a: 2, b: 1, expected: 3},
336-
> 19 | ])('.add($a, $b)', ({a, b, expected}) => {
337-
| ^
338-
20 | expect(a + b).toBe(expected);
339-
21 | });
340-
22 |
341-
342-
at ../../packages/jest-each/build/bind.js:38:11
343-
at Array.forEach (<anonymous>)
344-
at __tests__/worksWithOnlyMode.test.js:19:5
319+
320+
at each (__tests__/worksWithOnlyMode.test.js:15:19)
345321
at Object.describe (__tests__/worksWithOnlyMode.test.js:10:1)
346322
347323
● block with only, should fail › failing passes = fails, should fail

packages/jest-circus/src/index.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,19 @@ const test: Global.It = (() => {
147147
testName: Circus.TestNameLike,
148148
fn?: Circus.TestFn,
149149
timeout?: number,
150-
): void => _addTest(testName, mode, concurrent, fn, failing, timeout, true);
151-
failing.each = bindEach(failing, false);
150+
eachError?: Error,
151+
): void =>
152+
_addTest(
153+
testName,
154+
mode,
155+
concurrent,
156+
fn,
157+
failing,
158+
timeout,
159+
true,
160+
eachError,
161+
);
162+
failing.each = bindEach(failing, false, true);
152163
return failing;
153164
};
154165

@@ -175,8 +186,9 @@ const test: Global.It = (() => {
175186
) => void,
176187
timeout?: number,
177188
failing?: boolean,
189+
error?: Error,
178190
) => {
179-
const asyncError = new ErrorWithStack(undefined, testFn);
191+
const asyncError = error || new ErrorWithStack(undefined, testFn);
180192

181193
try {
182194
testName = convertDescriptorToString(testName);

packages/jest-each/src/bind.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,19 @@ type GlobalCallback = (
2626
testName: string,
2727
fn: Global.ConcurrentTestFn,
2828
timeout?: number,
29+
eachError?: Error,
2930
) => void;
3031

3132
export default function bind<EachCallback extends Global.TestCallback>(
3233
cb: GlobalCallback,
3334
supportsDone = true,
34-
) {
35+
needsEachError = false,
36+
): Global.EachTestFn<any> {
3537
const bindWrap = (
3638
table: Global.EachTable,
3739
...taggedTemplateData: Global.TemplateData
3840
) => {
39-
const error = new ErrorWithStack('', bindWrap);
41+
const error = new ErrorWithStack(undefined, bindWrap);
4042

4143
return function eachBind(
4244
title: Global.BlockNameLike,
@@ -50,16 +52,23 @@ export default function bind<EachCallback extends Global.TestCallback>(
5052
: buildTemplateTests(title, table, taggedTemplateData);
5153

5254
return tests.forEach(row =>
53-
cb(
54-
row.title,
55-
applyArguments(supportsDone, row.arguments, test),
56-
timeout,
57-
),
55+
needsEachError
56+
? cb(
57+
row.title,
58+
applyArguments(supportsDone, row.arguments, test),
59+
timeout,
60+
error,
61+
)
62+
: cb(
63+
row.title,
64+
applyArguments(supportsDone, row.arguments, test),
65+
timeout,
66+
),
5867
);
5968
} catch (e: any) {
6069
const err = new Error(e.message);
6170
err.stack = error.stack?.replace(/^Error: /s, e.message);
62-
err.name = e.name;
71+
err.name = '';
6372

6473
return cb(title, () => {
6574
throw err;

0 commit comments

Comments
 (0)