Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
liuxingbaoyu committed Oct 11, 2022
1 parent f45b04e commit a39810a
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 110 deletions.
174 changes: 75 additions & 99 deletions e2e/__tests__/__snapshots__/testFailing.test.ts.snap
Expand Up @@ -38,49 +38,43 @@ exports[`works with all statuses 1`] = `
Failing test passed even though it was supposed to fail. Remove \`.failing\` to remove error.
28 | });
29 |
> 30 | test.failing.each([
| ^
31 | {a: 1, b: 1, expected: 2},
32 | {a: 1, b: 2, expected: 3},
33 | {a: 2, b: 1, expected: 3},
> 34 | ])('.add($a, $b)', ({a, b, expected}) => {
| ^
35 | expect(a + b).toBe(expected);
36 | });
37 |
at ../../packages/jest-each/build/bind.js:38:11
at Array.forEach (<anonymous>)
at Object.<anonymous> (__tests__/statuses.test.js:34:3)
at Object.each (__tests__/statuses.test.js:30:14)
● .add(1, 2)
Failing test passed even though it was supposed to fail. Remove \`.failing\` to remove error.
28 | });
29 |
> 30 | test.failing.each([
| ^
31 | {a: 1, b: 1, expected: 2},
32 | {a: 1, b: 2, expected: 3},
33 | {a: 2, b: 1, expected: 3},
> 34 | ])('.add($a, $b)', ({a, b, expected}) => {
| ^
35 | expect(a + b).toBe(expected);
36 | });
37 |
at ../../packages/jest-each/build/bind.js:38:11
at Array.forEach (<anonymous>)
at Object.<anonymous> (__tests__/statuses.test.js:34:3)
at Object.each (__tests__/statuses.test.js:30:14)
● .add(2, 1)
Failing test passed even though it was supposed to fail. Remove \`.failing\` to remove error.
28 | });
29 |
> 30 | test.failing.each([
| ^
31 | {a: 1, b: 1, expected: 2},
32 | {a: 1, b: 2, expected: 3},
33 | {a: 2, b: 1, expected: 3},
> 34 | ])('.add($a, $b)', ({a, b, expected}) => {
| ^
35 | expect(a + b).toBe(expected);
36 | });
37 |
at ../../packages/jest-each/build/bind.js:38:11
at Array.forEach (<anonymous>)
at Object.<anonymous> (__tests__/statuses.test.js:34:3)
at Object.each (__tests__/statuses.test.js:30:14)
● failing passes = fails
Expand Down Expand Up @@ -127,51 +121,45 @@ exports[`works with concurrent and only mode 1`] = `
Failing test passed even though it was supposed to fail. Remove \`.failing\` to remove error.
15 | });
16 |
> 17 | test.concurrent.only.failing.each([
| ^
18 | {a: 1, b: 1, expected: 2},
19 | {a: 1, b: 2, expected: 3},
20 | {a: 2, b: 1, expected: 3},
> 21 | ])('.add($a, $b)', ({a, b, expected}) => {
| ^
22 | expect(a + b).toBe(expected);
23 | });
24 |
at ../../packages/jest-each/build/bind.js:38:11
at Array.forEach (<anonymous>)
at __tests__/worksWithConcurrentOnlyMode.test.js:21:5
at each (__tests__/worksWithConcurrentOnlyMode.test.js:17:32)
at Object.describe (__tests__/worksWithConcurrentOnlyMode.test.js:8:1)
● block with concurrent › .add(1, 2)
Failing test passed even though it was supposed to fail. Remove \`.failing\` to remove error.
15 | });
16 |
> 17 | test.concurrent.only.failing.each([
| ^
18 | {a: 1, b: 1, expected: 2},
19 | {a: 1, b: 2, expected: 3},
20 | {a: 2, b: 1, expected: 3},
> 21 | ])('.add($a, $b)', ({a, b, expected}) => {
| ^
22 | expect(a + b).toBe(expected);
23 | });
24 |
at ../../packages/jest-each/build/bind.js:38:11
at Array.forEach (<anonymous>)
at __tests__/worksWithConcurrentOnlyMode.test.js:21:5
at each (__tests__/worksWithConcurrentOnlyMode.test.js:17:32)
at Object.describe (__tests__/worksWithConcurrentOnlyMode.test.js:8:1)
● block with concurrent › .add(2, 1)
Failing test passed even though it was supposed to fail. Remove \`.failing\` to remove error.
15 | });
16 |
> 17 | test.concurrent.only.failing.each([
| ^
18 | {a: 1, b: 1, expected: 2},
19 | {a: 1, b: 2, expected: 3},
20 | {a: 2, b: 1, expected: 3},
> 21 | ])('.add($a, $b)', ({a, b, expected}) => {
| ^
22 | expect(a + b).toBe(expected);
23 | });
24 |
at ../../packages/jest-each/build/bind.js:38:11
at Array.forEach (<anonymous>)
at __tests__/worksWithConcurrentOnlyMode.test.js:21:5
at each (__tests__/worksWithConcurrentOnlyMode.test.js:17:32)
at Object.describe (__tests__/worksWithConcurrentOnlyMode.test.js:8:1)"
`;
Expand Down Expand Up @@ -222,51 +210,45 @@ exports[`works with concurrent mode 1`] = `
Failing test passed even though it was supposed to fail. Remove \`.failing\` to remove error.
15 | });
16 |
> 17 | test.concurrent.failing.each([
| ^
18 | {a: 1, b: 1, expected: 2},
19 | {a: 1, b: 2, expected: 3},
20 | {a: 2, b: 1, expected: 3},
> 21 | ])('.add($a, $b)', ({a, b, expected}) => {
| ^
22 | expect(a + b).toBe(expected);
23 | });
24 |
at ../../packages/jest-each/build/bind.js:38:11
at Array.forEach (<anonymous>)
at __tests__/worksWithConcurrentMode.test.js:21:5
at each (__tests__/worksWithConcurrentMode.test.js:17:27)
at Object.describe (__tests__/worksWithConcurrentMode.test.js:8:1)
● block with concurrent › .add(1, 2)
Failing test passed even though it was supposed to fail. Remove \`.failing\` to remove error.
15 | });
16 |
> 17 | test.concurrent.failing.each([
| ^
18 | {a: 1, b: 1, expected: 2},
19 | {a: 1, b: 2, expected: 3},
20 | {a: 2, b: 1, expected: 3},
> 21 | ])('.add($a, $b)', ({a, b, expected}) => {
| ^
22 | expect(a + b).toBe(expected);
23 | });
24 |
at ../../packages/jest-each/build/bind.js:38:11
at Array.forEach (<anonymous>)
at __tests__/worksWithConcurrentMode.test.js:21:5
at each (__tests__/worksWithConcurrentMode.test.js:17:27)
at Object.describe (__tests__/worksWithConcurrentMode.test.js:8:1)
● block with concurrent › .add(2, 1)
Failing test passed even though it was supposed to fail. Remove \`.failing\` to remove error.
15 | });
16 |
> 17 | test.concurrent.failing.each([
| ^
18 | {a: 1, b: 1, expected: 2},
19 | {a: 1, b: 2, expected: 3},
20 | {a: 2, b: 1, expected: 3},
> 21 | ])('.add($a, $b)', ({a, b, expected}) => {
| ^
22 | expect(a + b).toBe(expected);
23 | });
24 |
at ../../packages/jest-each/build/bind.js:38:11
at Array.forEach (<anonymous>)
at __tests__/worksWithConcurrentMode.test.js:21:5
at each (__tests__/worksWithConcurrentMode.test.js:17:27)
at Object.describe (__tests__/worksWithConcurrentMode.test.js:8:1)"
`;
Expand Down Expand Up @@ -297,51 +279,45 @@ exports[`works with only mode 1`] = `
Failing test passed even though it was supposed to fail. Remove \`.failing\` to remove error.
13 | });
14 |
> 15 | it.only.failing.each([
| ^
16 | {a: 1, b: 1, expected: 2},
17 | {a: 1, b: 2, expected: 3},
18 | {a: 2, b: 1, expected: 3},
> 19 | ])('.add($a, $b)', ({a, b, expected}) => {
| ^
20 | expect(a + b).toBe(expected);
21 | });
22 |
at ../../packages/jest-each/build/bind.js:38:11
at Array.forEach (<anonymous>)
at __tests__/worksWithOnlyMode.test.js:19:5
at each (__tests__/worksWithOnlyMode.test.js:15:19)
at Object.describe (__tests__/worksWithOnlyMode.test.js:10:1)
● block with only, should pass › .add(1, 2)
Failing test passed even though it was supposed to fail. Remove \`.failing\` to remove error.
13 | });
14 |
> 15 | it.only.failing.each([
| ^
16 | {a: 1, b: 1, expected: 2},
17 | {a: 1, b: 2, expected: 3},
18 | {a: 2, b: 1, expected: 3},
> 19 | ])('.add($a, $b)', ({a, b, expected}) => {
| ^
20 | expect(a + b).toBe(expected);
21 | });
22 |
at ../../packages/jest-each/build/bind.js:38:11
at Array.forEach (<anonymous>)
at __tests__/worksWithOnlyMode.test.js:19:5
at each (__tests__/worksWithOnlyMode.test.js:15:19)
at Object.describe (__tests__/worksWithOnlyMode.test.js:10:1)
● block with only, should pass › .add(2, 1)
Failing test passed even though it was supposed to fail. Remove \`.failing\` to remove error.
13 | });
14 |
> 15 | it.only.failing.each([
| ^
16 | {a: 1, b: 1, expected: 2},
17 | {a: 1, b: 2, expected: 3},
18 | {a: 2, b: 1, expected: 3},
> 19 | ])('.add($a, $b)', ({a, b, expected}) => {
| ^
20 | expect(a + b).toBe(expected);
21 | });
22 |
at ../../packages/jest-each/build/bind.js:38:11
at Array.forEach (<anonymous>)
at __tests__/worksWithOnlyMode.test.js:19:5
at each (__tests__/worksWithOnlyMode.test.js:15:19)
at Object.describe (__tests__/worksWithOnlyMode.test.js:10:1)
● block with only, should fail › failing passes = fails, should fail
Expand Down
18 changes: 15 additions & 3 deletions packages/jest-circus/src/index.ts
Expand Up @@ -147,8 +147,19 @@ const test: Global.It = (() => {
testName: Circus.TestNameLike,
fn?: Circus.TestFn,
timeout?: number,
): void => _addTest(testName, mode, concurrent, fn, failing, timeout, true);
failing.each = bindEach(failing, false);
eachError?: Error,
): void =>
_addTest(
testName,
mode,
concurrent,
fn,
failing,
timeout,
true,
eachError,
);
failing.each = bindEach(failing, false, true);
return failing;
};

Expand All @@ -175,8 +186,9 @@ const test: Global.It = (() => {
) => void,
timeout?: number,
failing?: boolean,
error?: Error,
) => {
const asyncError = new ErrorWithStack(undefined, testFn);
const asyncError = error || new ErrorWithStack(undefined, testFn);

try {
testName = convertDescriptorToString(testName);
Expand Down
25 changes: 17 additions & 8 deletions packages/jest-each/src/bind.ts
Expand Up @@ -26,17 +26,19 @@ type GlobalCallback = (
testName: string,
fn: Global.ConcurrentTestFn,
timeout?: number,
eachError?: Error,
) => void;

export default function bind<EachCallback extends Global.TestCallback>(
cb: GlobalCallback,
supportsDone = true,
) {
needsEachError = false,
): Global.EachTestFn<any> {
const bindWrap = (
table: Global.EachTable,
...taggedTemplateData: Global.TemplateData
) => {
const error = new ErrorWithStack('', bindWrap);
const error = new ErrorWithStack(undefined, bindWrap);

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

return tests.forEach(row =>
cb(
row.title,
applyArguments(supportsDone, row.arguments, test),
timeout,
),
needsEachError
? cb(
row.title,
applyArguments(supportsDone, row.arguments, test),
timeout,
error,
)
: cb(
row.title,
applyArguments(supportsDone, row.arguments, test),
timeout,
),
);
} catch (e: any) {
const err = new Error(e.message);
err.stack = error.stack?.replace(/^Error: /s, e.message);
err.name = e.name;
err.name = '';

return cb(title, () => {
throw err;
Expand Down

0 comments on commit a39810a

Please sign in to comment.