From da98463b88e4f7188bc2dd4571b307c9ce8d9c3e Mon Sep 17 00:00:00 2001 From: Yusuf Khan Date: Wed, 17 Aug 2022 03:06:53 +0530 Subject: [PATCH 01/11] feat(failing): added each to failing tests --- e2e/test-failing/__tests__/statuses.test.js | 8 ++++++++ .../__tests__/worksWithConcurrentMode.test.js | 8 ++++++++ .../__tests__/worksWithConcurrentOnlyMode.test.js | 8 ++++++++ e2e/test-failing/__tests__/worksWithOnlyMode.test.js | 8 ++++++++ e2e/test-failing/__tests__/worksWithSkipMode.test.js | 8 ++++++++ packages/jest-circus/src/index.ts | 8 +++++++- packages/jest-types/src/Global.ts | 9 +++++++-- 7 files changed, 54 insertions(+), 3 deletions(-) diff --git a/e2e/test-failing/__tests__/statuses.test.js b/e2e/test-failing/__tests__/statuses.test.js index a75235f1367b..45d15b671496 100644 --- a/e2e/test-failing/__tests__/statuses.test.js +++ b/e2e/test-failing/__tests__/statuses.test.js @@ -27,6 +27,14 @@ test.failing('failing fails = passes with test syntax', () => { expect(10).toBe(101); }); +test.failing.each([ + {a: 1, b: 1, expected: 2}, + {a: 1, b: 2, expected: 3}, + {a: 2, b: 1, expected: 3}, +])('.add($a, $b)', ({a, b, expected}) => { + expect(a + b).toBe(expected); +}); + it.skip.failing('skipped failing 1', () => { expect(10).toBe(10); }); diff --git a/e2e/test-failing/__tests__/worksWithConcurrentMode.test.js b/e2e/test-failing/__tests__/worksWithConcurrentMode.test.js index 950b01c29d08..8328d3d6c1f4 100644 --- a/e2e/test-failing/__tests__/worksWithConcurrentMode.test.js +++ b/e2e/test-failing/__tests__/worksWithConcurrentMode.test.js @@ -14,6 +14,14 @@ describe('block with concurrent', () => { expect(10).toBe(10); }); + test.concurrent.failing.each([ + {a: 1, b: 1, expected: 2}, + {a: 1, b: 2, expected: 3}, + {a: 2, b: 1, expected: 3}, + ])('.add($a, $b)', ({a, b, expected}) => { + expect(a + b).toBe(expected); + }); + it.concurrent.failing('failing fails = passes', () => { expect(10).toBe(101); }); diff --git a/e2e/test-failing/__tests__/worksWithConcurrentOnlyMode.test.js b/e2e/test-failing/__tests__/worksWithConcurrentOnlyMode.test.js index 93d8850d90ed..21b7af8e8d2d 100644 --- a/e2e/test-failing/__tests__/worksWithConcurrentOnlyMode.test.js +++ b/e2e/test-failing/__tests__/worksWithConcurrentOnlyMode.test.js @@ -14,6 +14,14 @@ describe('block with concurrent', () => { expect(10).toBe(10); }); + test.concurrent.only.failing.each([ + {a: 1, b: 1, expected: 2}, + {a: 1, b: 2, expected: 3}, + {a: 2, b: 1, expected: 3}, + ])('.add($a, $b)', ({a, b, expected}) => { + expect(a + b).toBe(expected); + }); + it.concurrent.only.failing('failing fails = passes', () => { expect(10).toBe(101); }); diff --git a/e2e/test-failing/__tests__/worksWithOnlyMode.test.js b/e2e/test-failing/__tests__/worksWithOnlyMode.test.js index d08dbc58315c..1e99bd80c640 100644 --- a/e2e/test-failing/__tests__/worksWithOnlyMode.test.js +++ b/e2e/test-failing/__tests__/worksWithOnlyMode.test.js @@ -10,6 +10,14 @@ describe('block with only, should pass', () => { expect(10).toBe(101); }); + it.only.failing.each([ + {a: 1, b: 1, expected: 2}, + {a: 1, b: 2, expected: 3}, + {a: 2, b: 1, expected: 3}, + ])('.add($a, $b)', ({a, b, expected}) => { + expect(a + b).toBe(expected); + }); + it('failing test but skipped', () => { expect(10).toBe(101); }); diff --git a/e2e/test-failing/__tests__/worksWithSkipMode.test.js b/e2e/test-failing/__tests__/worksWithSkipMode.test.js index 36cb4d1e43bd..164d3f9f02eb 100644 --- a/e2e/test-failing/__tests__/worksWithSkipMode.test.js +++ b/e2e/test-failing/__tests__/worksWithSkipMode.test.js @@ -10,6 +10,14 @@ describe('block with only, should pass', () => { expect(10).toBe(101); }); + it.skip.failing.each([ + {a: 1, b: 1, expected: 2}, + {a: 1, b: 2, expected: 3}, + {a: 2, b: 1, expected: 3}, + ])('.add($a, $b)', ({a, b, expected}) => { + expect(a + b).toBe(expected); + }); + it('failing test', () => { expect(10).toBe(101); }); diff --git a/packages/jest-circus/src/index.ts b/packages/jest-circus/src/index.ts index 21974ebc5e18..f472c7353162 100644 --- a/packages/jest-circus/src/index.ts +++ b/packages/jest-circus/src/index.ts @@ -5,6 +5,7 @@ * LICENSE file in the root directory of this source tree. */ +import type {Failing} from '@jest/types/src/Global'; import type {Circus, Global} from '@jest/types'; import {bind as bindEach} from 'jest-each'; import {ErrorWithStack, convertDescriptorToString, isPromise} from 'jest-util'; @@ -145,7 +146,7 @@ const test: Global.It = (() => { fn?: Circus.TestFn, timeout?: number, ): void => _addTest(testName, mode, concurrent, fn, failing, timeout, true); - return failing; + return failing as Failing; }; test.todo = (testName: Circus.TestNameLike, ...rest: Array): void => { @@ -213,16 +214,21 @@ const test: Global.It = (() => { concurrentOnly.each = bindEach(concurrentOnly, false); only.failing = bindFailing(false, 'only'); + only.failing.each = bindEach(only.failing, false); skip.failing = bindFailing(false, 'skip'); + skip.failing.each = bindEach(skip.failing, false); test.failing = bindFailing(false); + test.failing.each = bindEach(test.failing, false); test.only = only; test.skip = skip; test.concurrent = concurrentTest; concurrentTest.only = concurrentOnly; concurrentTest.skip = skip; concurrentTest.failing = bindFailing(true); + concurrentTest.failing.each = bindEach(concurrentTest.failing, false); concurrentOnly.failing = bindFailing(true, 'only'); + concurrentOnly.failing.each = bindEach(concurrentOnly.failing, false); return test; })(); diff --git a/packages/jest-types/src/Global.ts b/packages/jest-types/src/Global.ts index b99d659b4be7..8f9016dbb476 100644 --- a/packages/jest-types/src/Global.ts +++ b/packages/jest-types/src/Global.ts @@ -106,10 +106,15 @@ export interface HookBase { (fn: HookFn, timeout?: number): void; } +export interface Failing { + (testName?: TestNameLike, fn?: TestFn, timeout?: number): void | never; + each?: Each; +} + export interface ItBase { (testName: TestNameLike, fn: TestFn, timeout?: number): void; each: Each; - failing(testName: TestNameLike, fn: TestFn, timeout?: number): void; + failing: Failing; } export interface It extends ItBase { @@ -121,7 +126,7 @@ export interface It extends ItBase { export interface ItConcurrentBase { (testName: TestNameLike, testFn: ConcurrentTestFn, timeout?: number): void; each: Each; - failing(testName: TestNameLike, fn: ConcurrentTestFn, timeout?: number): void; + failing: Failing; } export interface ItConcurrentExtended extends ItConcurrentBase { From 102d9469462ca810c6c1bf8377e285d4402def39 Mon Sep 17 00:00:00 2001 From: Yusuf Khan Date: Wed, 17 Aug 2022 03:36:09 +0530 Subject: [PATCH 02/11] fixed(tests): udpated snapshots --- .../__snapshots__/testFailing.test.ts.snap | 306 +++++++++++++++--- 1 file changed, 261 insertions(+), 45 deletions(-) diff --git a/e2e/__tests__/__snapshots__/testFailing.test.ts.snap b/e2e/__tests__/__snapshots__/testFailing.test.ts.snap index d9772b8e05ae..516759332ef7 100644 --- a/e2e/__tests__/__snapshots__/testFailing.test.ts.snap +++ b/e2e/__tests__/__snapshots__/testFailing.test.ts.snap @@ -6,6 +6,9 @@ exports[`works with all statuses 1`] = ` ✕ fails ✓ failing fails = passes ✓ failing fails = passes with test syntax + ✕ .add(1, 1) + ✕ .add(1, 2) + ✕ .add(2, 1) ✕ failing passes = fails ○ skipped skips ○ skipped skipped failing 1 @@ -31,25 +34,76 @@ exports[`works with all statuses 1`] = ` at Object.toBe (__tests__/statuses.test.js:13:14) + ● .add(1, 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}, + + at ../../packages/jest-each/build/bind.js:45:11 + at Array.forEach () + at Object. (__tests__/statuses.test.js:30:1) + + ● .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}, + + at ../../packages/jest-each/build/bind.js:45:11 + at Array.forEach () + at Object. (__tests__/statuses.test.js:30:1) + + ● .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}, + + at ../../packages/jest-each/build/bind.js:45:11 + at Array.forEach () + at Object. (__tests__/statuses.test.js:30:1) + ● failing passes = fails Failing test passed even though it was supposed to fail. Remove \`.failing\` to remove error. - 36 | }); - 37 | - > 38 | it.failing('failing passes = fails', () => { + 44 | }); + 45 | + > 46 | it.failing('failing passes = fails', () => { | ^ - 39 | expect(10).toBe(10); - 40 | }); - 41 | + 47 | expect(10).toBe(10); + 48 | }); + 49 | - at Object.failing (__tests__/statuses.test.js:38:4)" + at Object.failing (__tests__/statuses.test.js:46:4)" `; exports[`works with concurrent and only mode 1`] = ` "FAIL __tests__/worksWithConcurrentOnlyMode.test.js block with concurrent ✕ failing passes = fails + ✕ .add(1, 1) + ✕ .add(1, 2) + ✕ .add(2, 1) ✓ failing fails = passes ○ skipped skipped failing test ○ skipped skipped failing fails @@ -67,6 +121,57 @@ exports[`works with concurrent and only mode 1`] = ` 16 | at failing (__tests__/worksWithConcurrentOnlyMode.test.js:13:22) + at Object.describe (__tests__/worksWithConcurrentOnlyMode.test.js:8:1) + + ● block with concurrent › .add(1, 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}, + + at ../../packages/jest-each/build/bind.js:45:11 + at Array.forEach () + at __tests__/worksWithConcurrentOnlyMode.test.js:17:3 + 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}, + + at ../../packages/jest-each/build/bind.js:45:11 + at Array.forEach () + at __tests__/worksWithConcurrentOnlyMode.test.js:17:3 + 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}, + + at ../../packages/jest-each/build/bind.js:45:11 + at Array.forEach () + at __tests__/worksWithConcurrentOnlyMode.test.js:17:3 at Object.describe (__tests__/worksWithConcurrentOnlyMode.test.js:8:1)" `; @@ -75,6 +180,9 @@ exports[`works with concurrent mode 1`] = ` block with concurrent ✕ failing test ✕ failing passes = fails + ✕ .add(1, 1) + ✕ .add(1, 2) + ✕ .add(2, 1) ✓ failing fails = passes ○ skipped skipped failing fails @@ -108,6 +216,57 @@ exports[`works with concurrent mode 1`] = ` 16 | at failing (__tests__/worksWithConcurrentMode.test.js:13:17) + at Object.describe (__tests__/worksWithConcurrentMode.test.js:8:1) + + ● block with concurrent › .add(1, 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}, + + at ../../packages/jest-each/build/bind.js:45:11 + at Array.forEach () + at __tests__/worksWithConcurrentMode.test.js:17:3 + 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}, + + at ../../packages/jest-each/build/bind.js:45:11 + at Array.forEach () + at __tests__/worksWithConcurrentMode.test.js:17:3 + 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}, + + at ../../packages/jest-each/build/bind.js:45:11 + at Array.forEach () + at __tests__/worksWithConcurrentMode.test.js:17:3 at Object.describe (__tests__/worksWithConcurrentMode.test.js:8:1)" `; @@ -115,6 +274,9 @@ exports[`works with only mode 1`] = ` "FAIL __tests__/worksWithOnlyMode.test.js block with only, should pass ✓ failing fails = passes, should pass + ✕ .add(1, 1) + ✕ .add(1, 2) + ✕ .add(2, 1) ○ skipped failing test but skipped ○ skipped passing test but skipped block with only, should fail @@ -131,20 +293,71 @@ exports[`works with only mode 1`] = ` ○ skipped failing test but skipped ○ skipped passing test but skipped + ● block with only, should pass › .add(1, 1) + + Failing test passed even though it was supposed to fail. Remove \`.failing\` to remove error. + + 11 | }); + 12 | + > 13 | it.only.failing.each([ + | ^ + 14 | {a: 1, b: 1, expected: 2}, + 15 | {a: 1, b: 2, expected: 3}, + 16 | {a: 2, b: 1, expected: 3}, + + at ../../packages/jest-each/build/bind.js:45:11 + at Array.forEach () + at __tests__/worksWithOnlyMode.test.js:13:3 + at Object.describe (__tests__/worksWithOnlyMode.test.js:8:1) + + ● block with only, should pass › .add(1, 2) + + Failing test passed even though it was supposed to fail. Remove \`.failing\` to remove error. + + 11 | }); + 12 | + > 13 | it.only.failing.each([ + | ^ + 14 | {a: 1, b: 1, expected: 2}, + 15 | {a: 1, b: 2, expected: 3}, + 16 | {a: 2, b: 1, expected: 3}, + + at ../../packages/jest-each/build/bind.js:45:11 + at Array.forEach () + at __tests__/worksWithOnlyMode.test.js:13:3 + at Object.describe (__tests__/worksWithOnlyMode.test.js:8:1) + + ● block with only, should pass › .add(2, 1) + + Failing test passed even though it was supposed to fail. Remove \`.failing\` to remove error. + + 11 | }); + 12 | + > 13 | it.only.failing.each([ + | ^ + 14 | {a: 1, b: 1, expected: 2}, + 15 | {a: 1, b: 2, expected: 3}, + 16 | {a: 2, b: 1, expected: 3}, + + at ../../packages/jest-each/build/bind.js:45:11 + at Array.forEach () + at __tests__/worksWithOnlyMode.test.js:13:3 + at Object.describe (__tests__/worksWithOnlyMode.test.js:8:1) + ● block with only, should fail › failing passes = fails, should fail Failing test passed even though it was supposed to fail. Remove \`.failing\` to remove error. - 21 | - 22 | describe('block with only, should fail', () => { - > 23 | it.only.failing('failing passes = fails, should fail', () => { + 29 | + 30 | describe('block with only, should fail', () => { + > 31 | it.only.failing('failing passes = fails, should fail', () => { | ^ - 24 | expect(10).toBe(10); - 25 | }); - 26 | + 32 | expect(10).toBe(10); + 33 | }); + 34 | - at failing (__tests__/worksWithOnlyMode.test.js:23:11) - at Object.describe (__tests__/worksWithOnlyMode.test.js:22:1) + at failing (__tests__/worksWithOnlyMode.test.js:31:11) + at Object.describe (__tests__/worksWithOnlyMode.test.js:30:1) ● block with only in other it, should skip › failing test @@ -153,45 +366,45 @@ exports[`works with only mode 1`] = ` Expected: 101 Received: 10 - 40 | - 41 | it.only('failing test', () => { - > 42 | expect(10).toBe(101); + 48 | + 49 | it.only('failing test', () => { + > 50 | expect(10).toBe(101); | ^ - 43 | }); - 44 | - 45 | it('passing test but skipped', () => { + 51 | }); + 52 | + 53 | it('passing test but skipped', () => { - at Object.toBe (__tests__/worksWithOnlyMode.test.js:42:16) + at Object.toBe (__tests__/worksWithOnlyMode.test.js:50:16) ● block with only with different syntax, should fail › failing passes = fails, should fail 1 Failing test passed even though it was supposed to fail. Remove \`.failing\` to remove error. - 49 | - 50 | describe('block with only with different syntax, should fail', () => { - > 51 | fit.failing('failing passes = fails, should fail 1', () => { + 57 | + 58 | describe('block with only with different syntax, should fail', () => { + > 59 | fit.failing('failing passes = fails, should fail 1', () => { | ^ - 52 | expect(10).toBe(10); - 53 | }); - 54 | + 60 | expect(10).toBe(10); + 61 | }); + 62 | - at failing (__tests__/worksWithOnlyMode.test.js:51:7) - at Object.describe (__tests__/worksWithOnlyMode.test.js:50:1) + at failing (__tests__/worksWithOnlyMode.test.js:59:7) + at Object.describe (__tests__/worksWithOnlyMode.test.js:58:1) ● block with only with different syntax, should fail › failing passes = fails, should fail 2 Failing test passed even though it was supposed to fail. Remove \`.failing\` to remove error. - 53 | }); - 54 | - > 55 | test.only.failing('failing passes = fails, should fail 2', () => { + 61 | }); + 62 | + > 63 | test.only.failing('failing passes = fails, should fail 2', () => { | ^ - 56 | expect(10).toBe(10); - 57 | }); - 58 | + 64 | expect(10).toBe(10); + 65 | }); + 66 | - at failing (__tests__/worksWithOnlyMode.test.js:55:13) - at Object.describe (__tests__/worksWithOnlyMode.test.js:50:1)" + at failing (__tests__/worksWithOnlyMode.test.js:63:13) + at Object.describe (__tests__/worksWithOnlyMode.test.js:58:1)" `; exports[`works with skip mode 1`] = ` @@ -200,6 +413,9 @@ exports[`works with skip mode 1`] = ` ✕ failing test ✓ failing fails = passes ○ skipped skipped failing fails = passes, should pass + ○ skipped .add(1, 1) + ○ skipped .add(1, 2) + ○ skipped .add(2, 1) ○ skipped passing test block with only, should fail ✓ passing test @@ -214,13 +430,13 @@ exports[`works with skip mode 1`] = ` Expected: 101 Received: 10 - 12 | - 13 | it('failing test', () => { - > 14 | expect(10).toBe(101); + 20 | + 21 | it('failing test', () => { + > 22 | expect(10).toBe(101); | ^ - 15 | }); - 16 | - 17 | it.skip('passing test', () => { + 23 | }); + 24 | + 25 | it.skip('passing test', () => { - at Object.toBe (__tests__/worksWithSkipMode.test.js:14:16)" + at Object.toBe (__tests__/worksWithSkipMode.test.js:22:16)" `; From 8bb7b1cbd06be5cb5f34aa2b04f96e3eeae9d61a Mon Sep 17 00:00:00 2001 From: Yusuf Khan Date: Wed, 17 Aug 2022 11:54:24 +0530 Subject: [PATCH 03/11] fix(tests): updated snapshots --- .../testFailingJasmine.test.ts.snap | 94 ++++++++++++------- 1 file changed, 62 insertions(+), 32 deletions(-) diff --git a/e2e/__tests__/__snapshots__/testFailingJasmine.test.ts.snap b/e2e/__tests__/__snapshots__/testFailingJasmine.test.ts.snap index 2760cfd57937..9e86df21db7c 100644 --- a/e2e/__tests__/__snapshots__/testFailingJasmine.test.ts.snap +++ b/e2e/__tests__/__snapshots__/testFailingJasmine.test.ts.snap @@ -34,6 +34,21 @@ FAIL __tests__/worksWithConcurrentMode.test.js at Object.toBe (__tests__/worksWithConcurrentMode.test.js:10:16) + ● block with concurrent › encountered a declaration exception + + TypeError: test.concurrent.failing.each is not a function + + 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}, + + at Suite.each (__tests__/worksWithConcurrentMode.test.js:17:27) + at Object.describe (__tests__/worksWithConcurrentMode.test.js:8:1) + FAIL __tests__/worksWithConcurrentOnlyMode.test.js ● block with concurrent › skipped failing test @@ -52,6 +67,21 @@ FAIL __tests__/worksWithConcurrentOnlyMode.test.js at Object.toBe (__tests__/worksWithConcurrentOnlyMode.test.js:10:16) + ● block with concurrent › encountered a declaration exception + + TypeError: test.concurrent.only.failing.each is not a function + + 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}, + + at Suite.each (__tests__/worksWithConcurrentOnlyMode.test.js:17:32) + at Object.describe (__tests__/worksWithConcurrentOnlyMode.test.js:8:1) + FAIL __tests__/worksWithOnlyMode.test.js ● block with only, should pass › encountered a declaration exception @@ -72,46 +102,46 @@ FAIL __tests__/worksWithOnlyMode.test.js Jest: \`failing\` tests are only supported in \`jest-circus\`. - 21 | - 22 | describe('block with only, should fail', () => { - > 23 | it.only.failing('failing passes = fails, should fail', () => { + 29 | + 30 | describe('block with only, should fail', () => { + > 31 | it.only.failing('failing passes = fails, should fail', () => { | ^ - 24 | expect(10).toBe(10); - 25 | }); - 26 | + 32 | expect(10).toBe(10); + 33 | }); + 34 | - at Suite.failing (__tests__/worksWithOnlyMode.test.js:23:11) - at Object.describe (__tests__/worksWithOnlyMode.test.js:22:1) + at Suite.failing (__tests__/worksWithOnlyMode.test.js:31:11) + at Object.describe (__tests__/worksWithOnlyMode.test.js:30:1) ● block with only in other it, should skip › encountered a declaration exception Jest: \`failing\` tests are only supported in \`jest-circus\`. - 35 | - 36 | describe('block with only in other it, should skip', () => { - > 37 | it.failing('failing passes = fails, should fail but skipped', () => { + 43 | + 44 | describe('block with only in other it, should skip', () => { + > 45 | it.failing('failing passes = fails, should fail but skipped', () => { | ^ - 38 | expect(10).toBe(10); - 39 | }); - 40 | + 46 | expect(10).toBe(10); + 47 | }); + 48 | - at Suite.failing (__tests__/worksWithOnlyMode.test.js:37:6) - at Object.describe (__tests__/worksWithOnlyMode.test.js:36:1) + at Suite.failing (__tests__/worksWithOnlyMode.test.js:45:6) + at Object.describe (__tests__/worksWithOnlyMode.test.js:44:1) ● block with only with different syntax, should fail › encountered a declaration exception Jest: \`failing\` tests are only supported in \`jest-circus\`. - 49 | - 50 | describe('block with only with different syntax, should fail', () => { - > 51 | fit.failing('failing passes = fails, should fail 1', () => { + 57 | + 58 | describe('block with only with different syntax, should fail', () => { + > 59 | fit.failing('failing passes = fails, should fail 1', () => { | ^ - 52 | expect(10).toBe(10); - 53 | }); - 54 | + 60 | expect(10).toBe(10); + 61 | }); + 62 | - at Suite.failing (__tests__/worksWithOnlyMode.test.js:51:7) - at Object.describe (__tests__/worksWithOnlyMode.test.js:50:1) + at Suite.failing (__tests__/worksWithOnlyMode.test.js:59:7) + at Object.describe (__tests__/worksWithOnlyMode.test.js:58:1) FAIL __tests__/worksWithSkipMode.test.js ● block with only, should pass › encountered a declaration exception @@ -133,14 +163,14 @@ FAIL __tests__/worksWithSkipMode.test.js Jest: \`failing\` tests are only supported in \`jest-circus\`. - 25 | - 26 | describe('block with only, should fail', () => { - > 27 | it.skip.failing('failing passes = fails, should fail', () => { + 33 | + 34 | describe('block with only, should fail', () => { + > 35 | it.skip.failing('failing passes = fails, should fail', () => { | ^ - 28 | expect(10).toBe(10); - 29 | }); - 30 | + 36 | expect(10).toBe(10); + 37 | }); + 38 | - at Suite.failing (__tests__/worksWithSkipMode.test.js:27:11) - at Object.describe (__tests__/worksWithSkipMode.test.js:26:1)" + at Suite.failing (__tests__/worksWithSkipMode.test.js:35:11) + at Object.describe (__tests__/worksWithSkipMode.test.js:34:1)" `; From 72ce800f578151268cd7dd1b9796bfe863fe100f Mon Sep 17 00:00:00 2001 From: Yusuf Khan Date: Wed, 17 Aug 2022 18:03:38 +0530 Subject: [PATCH 04/11] feat(tests): updated snapshots, added docs --- CHANGELOG.md | 1 + docs/GlobalAPI.md | 26 +- .../testFailingJasmine.test.ts.snap | 340 ++++++++++++++---- packages/jest-circus/src/index.ts | 10 +- packages/jest-types/src/Global.ts | 8 +- 5 files changed, 294 insertions(+), 91 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c20e4d2a0c4d..9d5e065e2cd5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ### Features +- `[jest-circus]` Add `each` for failing tests ([#13142](https://github.com/facebook/jest/pull/13142)). It adds this functionality on top of previously added `failing` feature in ([#12610](https://github.com/facebook/jest/pull/12610)). - `[jest-config]` [**BREAKING**] Make `snapshotFormat` default to `escapeString: false` and `printBasicPrototype: false` ([#13036](https://github.com/facebook/jest/pull/13036)) - `[jest-environment-jsdom]` [**BREAKING**] Upgrade to `jsdom@20` ([#13037](https://github.com/facebook/jest/pull/13037), [#13058](https://github.com/facebook/jest/pull/13058)) - `[@jest/globals]` Add `jest.Mocked`, `jest.MockedClass`, `jest.MockedFunction` and `jest.MockedObject` utility types ([#12727](https://github.com/facebook/jest/pull/12727)) diff --git a/docs/GlobalAPI.md b/docs/GlobalAPI.md index ad68f1389c15..479c0d629b20 100644 --- a/docs/GlobalAPI.md +++ b/docs/GlobalAPI.md @@ -735,17 +735,11 @@ test.each` Also under the alias: `it.failing(name, fn, timeout)` -:::note - -This is only available with the default [jest-circus](https://github.com/facebook/jest/tree/main/packages/jest-circus) runner. - -::: +> Note: This is only available with the default [jest-circus](https://github.com/facebook/jest/tree/main/packages/jest-circus) runner. Use `test.failing` when you are writing a test and expecting it to fail. These tests will behave the other way normal tests do. If `failing` test will throw any errors then it will pass. If it does not throw it will fail. -:::tip - -You can use this type of tests i.e. when writing code in a BDD way. In that case the tests will not show up as failing until they pass. Then you can just remove the `failing` modifier to make them pass. +> Tip: You can use this type of tests i.e. when writing code in a BDD way. In that case the tests will not show up as failing until they pass. Then you can just remove the `failing` modifier to make them pass. It can also be a nice way to contribute failing tests to a project, even if you don't know how to fix the bug. @@ -763,6 +757,22 @@ test.failing('it is equal', () => { }); ``` +### `test.failing.each(name, fn, timeout)` + +We can also run multiple tests at once by adding `each` after `failing`. + +Example: + +```js +test.failing.each([ + {a: 1, b: 1, expected: 2}, + {a: 1, b: 2, expected: 3}, + {a: 2, b: 1, expected: 3}, + ])('.add($a, $b)', ({a, b, expected}) => { + expect(a + b).toBe(expected); + }); +``` + ### `test.only.failing(name, fn, timeout)` Also under the aliases: `it.only.failing(name, fn, timeout)`, `fit.failing(name, fn, timeout)` diff --git a/e2e/__tests__/__snapshots__/testFailingJasmine.test.ts.snap b/e2e/__tests__/__snapshots__/testFailingJasmine.test.ts.snap index 9e86df21db7c..aef1f69ab33b 100644 --- a/e2e/__tests__/__snapshots__/testFailingJasmine.test.ts.snap +++ b/e2e/__tests__/__snapshots__/testFailingJasmine.test.ts.snap @@ -2,19 +2,84 @@ exports[`throws an error about unsupported modifier 1`] = ` "FAIL __tests__/statuses.test.js - ● Test suite failed to run + ● fails - Jest: \`failing\` tests are only supported in \`jest-circus\`. + expect(received).toBe(expected) // Object.is equality + + Expected: 101 + Received: 10 + + 11 | + 12 | it('fails', () => { + > 13 | expect(10).toBe(101); + | ^ + 14 | }); + 15 | + 16 | it.skip('skips', () => { + + at Object.toBe (__tests__/statuses.test.js:13:14) + + ● .add(1, 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}, + + at ../../packages/jest-each/build/bind.js:45:11 + at Array.forEach () + at Object. (__tests__/statuses.test.js:30:1) + + ● .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}, - 20 | it.todo('todo'); - 21 | - > 22 | it.failing('failing fails = passes', () => { + at ../../packages/jest-each/build/bind.js:45:11 + at Array.forEach () + at Object. (__tests__/statuses.test.js:30:1) + + ● .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}, + + at ../../packages/jest-each/build/bind.js:45:11 + at Array.forEach () + at Object. (__tests__/statuses.test.js:30:1) + + ● failing passes = fails + + Failing test passed even though it was supposed to fail. Remove \`.failing\` to remove error. + + 44 | }); + 45 | + > 46 | it.failing('failing passes = fails', () => { | ^ - 23 | expect(10).toBe(101); - 24 | }); - 25 | + 47 | expect(10).toBe(10); + 48 | }); + 49 | - at Object.failing (__tests__/statuses.test.js:22:4) + at Object.failing (__tests__/statuses.test.js:46:4) FAIL __tests__/worksWithConcurrentMode.test.js ● block with concurrent › failing test @@ -34,73 +99,194 @@ FAIL __tests__/worksWithConcurrentMode.test.js at Object.toBe (__tests__/worksWithConcurrentMode.test.js:10:16) - ● block with concurrent › encountered a declaration exception + ● block with concurrent › failing passes = fails - TypeError: test.concurrent.failing.each is not a function + Failing test passed even though it was supposed to fail. Remove \`.failing\` to remove error. + + 11 | }); + 12 | + > 13 | it.concurrent.failing('failing passes = fails', () => { + | ^ + 14 | expect(10).toBe(10); + 15 | }); + 16 | + + at failing (__tests__/worksWithConcurrentMode.test.js:13:17) + at Object.describe (__tests__/worksWithConcurrentMode.test.js:8:1) + + ● block with concurrent › .add(1, 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}, - at Suite.each (__tests__/worksWithConcurrentMode.test.js:17:27) + at ../../packages/jest-each/build/bind.js:45:11 + at Array.forEach () + at __tests__/worksWithConcurrentMode.test.js:17:3 at Object.describe (__tests__/worksWithConcurrentMode.test.js:8:1) -FAIL __tests__/worksWithConcurrentOnlyMode.test.js - ● block with concurrent › skipped failing test + ● block with concurrent › .add(1, 2) - expect(received).toBe(expected) // Object.is equality + Failing test passed even though it was supposed to fail. Remove \`.failing\` to remove error. - Expected: 101 - Received: 10 + 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}, + + at ../../packages/jest-each/build/bind.js:45:11 + at Array.forEach () + at __tests__/worksWithConcurrentMode.test.js:17:3 + 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}, + + at ../../packages/jest-each/build/bind.js:45:11 + at Array.forEach () + at __tests__/worksWithConcurrentMode.test.js:17:3 + at Object.describe (__tests__/worksWithConcurrentMode.test.js:8:1) + +FAIL __tests__/worksWithConcurrentOnlyMode.test.js + ● block with concurrent › failing passes = fails + + Failing test passed even though it was supposed to fail. Remove \`.failing\` to remove error. - 8 | describe('block with concurrent', () => { - 9 | it('skipped failing test', () => { - > 10 | expect(10).toBe(101); - | ^ 11 | }); 12 | - 13 | it.concurrent.only.failing('failing passes = fails', () => { + > 13 | it.concurrent.only.failing('failing passes = fails', () => { + | ^ + 14 | expect(10).toBe(10); + 15 | }); + 16 | - at Object.toBe (__tests__/worksWithConcurrentOnlyMode.test.js:10:16) + at failing (__tests__/worksWithConcurrentOnlyMode.test.js:13:22) + at Object.describe (__tests__/worksWithConcurrentOnlyMode.test.js:8:1) - ● block with concurrent › encountered a declaration exception + ● block with concurrent › .add(1, 1) - TypeError: test.concurrent.only.failing.each is not a function + 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}, - at Suite.each (__tests__/worksWithConcurrentOnlyMode.test.js:17:32) + at ../../packages/jest-each/build/bind.js:45:11 + at Array.forEach () + at __tests__/worksWithConcurrentOnlyMode.test.js:17:3 + 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}, + + at ../../packages/jest-each/build/bind.js:45:11 + at Array.forEach () + at __tests__/worksWithConcurrentOnlyMode.test.js:17:3 + 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}, + + at ../../packages/jest-each/build/bind.js:45:11 + at Array.forEach () + at __tests__/worksWithConcurrentOnlyMode.test.js:17:3 at Object.describe (__tests__/worksWithConcurrentOnlyMode.test.js:8:1) FAIL __tests__/worksWithOnlyMode.test.js - ● block with only, should pass › encountered a declaration exception + ● block with only, should pass › .add(1, 1) - Jest: \`failing\` tests are only supported in \`jest-circus\`. + Failing test passed even though it was supposed to fail. Remove \`.failing\` to remove error. + + 11 | }); + 12 | + > 13 | it.only.failing.each([ + | ^ + 14 | {a: 1, b: 1, expected: 2}, + 15 | {a: 1, b: 2, expected: 3}, + 16 | {a: 2, b: 1, expected: 3}, + + at ../../packages/jest-each/build/bind.js:45:11 + at Array.forEach () + at __tests__/worksWithOnlyMode.test.js:13:3 + at Object.describe (__tests__/worksWithOnlyMode.test.js:8:1) + + ● block with only, should pass › .add(1, 2) + + Failing test passed even though it was supposed to fail. Remove \`.failing\` to remove error. - 7 | - 8 | describe('block with only, should pass', () => { - > 9 | it.only.failing('failing fails = passes, should pass', () => { - | ^ - 10 | expect(10).toBe(101); 11 | }); 12 | + > 13 | it.only.failing.each([ + | ^ + 14 | {a: 1, b: 1, expected: 2}, + 15 | {a: 1, b: 2, expected: 3}, + 16 | {a: 2, b: 1, expected: 3}, + + at ../../packages/jest-each/build/bind.js:45:11 + at Array.forEach () + at __tests__/worksWithOnlyMode.test.js:13:3 + at Object.describe (__tests__/worksWithOnlyMode.test.js:8:1) + + ● block with only, should pass › .add(2, 1) + + Failing test passed even though it was supposed to fail. Remove \`.failing\` to remove error. - at Suite.failing (__tests__/worksWithOnlyMode.test.js:9:11) + 11 | }); + 12 | + > 13 | it.only.failing.each([ + | ^ + 14 | {a: 1, b: 1, expected: 2}, + 15 | {a: 1, b: 2, expected: 3}, + 16 | {a: 2, b: 1, expected: 3}, + + at ../../packages/jest-each/build/bind.js:45:11 + at Array.forEach () + at __tests__/worksWithOnlyMode.test.js:13:3 at Object.describe (__tests__/worksWithOnlyMode.test.js:8:1) - ● block with only, should fail › encountered a declaration exception + ● block with only, should fail › failing passes = fails, should fail - Jest: \`failing\` tests are only supported in \`jest-circus\`. + Failing test passed even though it was supposed to fail. Remove \`.failing\` to remove error. 29 | 30 | describe('block with only, should fail', () => { @@ -110,27 +296,29 @@ FAIL __tests__/worksWithOnlyMode.test.js 33 | }); 34 | - at Suite.failing (__tests__/worksWithOnlyMode.test.js:31:11) + at failing (__tests__/worksWithOnlyMode.test.js:31:11) at Object.describe (__tests__/worksWithOnlyMode.test.js:30:1) - ● block with only in other it, should skip › encountered a declaration exception + ● block with only in other it, should skip › failing test - Jest: \`failing\` tests are only supported in \`jest-circus\`. + expect(received).toBe(expected) // Object.is equality + + Expected: 101 + Received: 10 - 43 | - 44 | describe('block with only in other it, should skip', () => { - > 45 | it.failing('failing passes = fails, should fail but skipped', () => { - | ^ - 46 | expect(10).toBe(10); - 47 | }); 48 | + 49 | it.only('failing test', () => { + > 50 | expect(10).toBe(101); + | ^ + 51 | }); + 52 | + 53 | it('passing test but skipped', () => { - at Suite.failing (__tests__/worksWithOnlyMode.test.js:45:6) - at Object.describe (__tests__/worksWithOnlyMode.test.js:44:1) + at Object.toBe (__tests__/worksWithOnlyMode.test.js:50:16) - ● block with only with different syntax, should fail › encountered a declaration exception + ● block with only with different syntax, should fail › failing passes = fails, should fail 1 - Jest: \`failing\` tests are only supported in \`jest-circus\`. + Failing test passed even though it was supposed to fail. Remove \`.failing\` to remove error. 57 | 58 | describe('block with only with different syntax, should fail', () => { @@ -140,37 +328,39 @@ FAIL __tests__/worksWithOnlyMode.test.js 61 | }); 62 | - at Suite.failing (__tests__/worksWithOnlyMode.test.js:59:7) + at failing (__tests__/worksWithOnlyMode.test.js:59:7) at Object.describe (__tests__/worksWithOnlyMode.test.js:58:1) -FAIL __tests__/worksWithSkipMode.test.js - ● block with only, should pass › encountered a declaration exception + ● block with only with different syntax, should fail › failing passes = fails, should fail 2 - Jest: \`failing\` tests are only supported in \`jest-circus\`. + Failing test passed even though it was supposed to fail. Remove \`.failing\` to remove error. - 7 | - 8 | describe('block with only, should pass', () => { - > 9 | it.skip.failing('skipped failing fails = passes, should pass', () => { - | ^ - 10 | expect(10).toBe(101); - 11 | }); - 12 | + 61 | }); + 62 | + > 63 | test.only.failing('failing passes = fails, should fail 2', () => { + | ^ + 64 | expect(10).toBe(10); + 65 | }); + 66 | + + at failing (__tests__/worksWithOnlyMode.test.js:63:13) + at Object.describe (__tests__/worksWithOnlyMode.test.js:58:1) - at Suite.failing (__tests__/worksWithSkipMode.test.js:9:11) - at Object.describe (__tests__/worksWithSkipMode.test.js:8:1) +FAIL __tests__/worksWithSkipMode.test.js + ● block with only, should pass › failing test - ● block with only, should fail › encountered a declaration exception + expect(received).toBe(expected) // Object.is equality - Jest: \`failing\` tests are only supported in \`jest-circus\`. + Expected: 101 + Received: 10 - 33 | - 34 | describe('block with only, should fail', () => { - > 35 | it.skip.failing('failing passes = fails, should fail', () => { - | ^ - 36 | expect(10).toBe(10); - 37 | }); - 38 | + 20 | + 21 | it('failing test', () => { + > 22 | expect(10).toBe(101); + | ^ + 23 | }); + 24 | + 25 | it.skip('passing test', () => { - at Suite.failing (__tests__/worksWithSkipMode.test.js:35:11) - at Object.describe (__tests__/worksWithSkipMode.test.js:34:1)" + at Object.toBe (__tests__/worksWithSkipMode.test.js:22:16)" `; diff --git a/packages/jest-circus/src/index.ts b/packages/jest-circus/src/index.ts index f472c7353162..ed3aab310a3d 100644 --- a/packages/jest-circus/src/index.ts +++ b/packages/jest-circus/src/index.ts @@ -5,8 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -import type {Failing} from '@jest/types/src/Global'; -import type {Circus, Global} from '@jest/types'; +import {Circus, Global} from '@jest/types'; import {bind as bindEach} from 'jest-each'; import {ErrorWithStack, convertDescriptorToString, isPromise} from 'jest-util'; import {dispatchSync} from './state'; @@ -141,12 +140,15 @@ const test: Global.It = (() => { ): void => _addTest(testName, 'only', true, fn, concurrentOnly, timeout); const bindFailing = (concurrent: boolean, mode: Circus.TestMode) => { - const failing = ( + type FailingReturn = typeof concurrent extends true + ? Global.ConcurrentTestFn + : Global.TestFn; + const failing: Global.Failing = ( testName: Circus.TestNameLike, fn?: Circus.TestFn, timeout?: number, ): void => _addTest(testName, mode, concurrent, fn, failing, timeout, true); - return failing as Failing; + return failing; }; test.todo = (testName: Circus.TestNameLike, ...rest: Array): void => { diff --git a/packages/jest-types/src/Global.ts b/packages/jest-types/src/Global.ts index 8f9016dbb476..bc400992216b 100644 --- a/packages/jest-types/src/Global.ts +++ b/packages/jest-types/src/Global.ts @@ -106,15 +106,15 @@ export interface HookBase { (fn: HookFn, timeout?: number): void; } -export interface Failing { - (testName?: TestNameLike, fn?: TestFn, timeout?: number): void | never; +export interface Failing { + (testName: TestNameLike, fn: T, timeout?: number): void; each?: Each; } export interface ItBase { (testName: TestNameLike, fn: TestFn, timeout?: number): void; each: Each; - failing: Failing; + failing: Failing; } export interface It extends ItBase { @@ -126,7 +126,7 @@ export interface It extends ItBase { export interface ItConcurrentBase { (testName: TestNameLike, testFn: ConcurrentTestFn, timeout?: number): void; each: Each; - failing: Failing; + failing: Failing; } export interface ItConcurrentExtended extends ItConcurrentBase { From d6ed1fccf15a07cde7285c5d552a31b247cbe269 Mon Sep 17 00:00:00 2001 From: Yusuf Khan Date: Wed, 17 Aug 2022 20:09:31 +0530 Subject: [PATCH 05/11] fixed(tests): updated snapshots --- docs/GlobalAPI.md | 10 +- .../testFailingJasmine.test.ts.snap | 342 ++++-------------- packages/jest-circus/src/index.ts | 2 +- packages/jest-jasmine2/src/index.ts | 7 + .../jest-jasmine2/src/jasmineAsyncInstall.ts | 17 +- 5 files changed, 106 insertions(+), 272 deletions(-) diff --git a/docs/GlobalAPI.md b/docs/GlobalAPI.md index 479c0d629b20..8fb7f3842a7c 100644 --- a/docs/GlobalAPI.md +++ b/docs/GlobalAPI.md @@ -735,11 +735,17 @@ test.each` Also under the alias: `it.failing(name, fn, timeout)` -> Note: This is only available with the default [jest-circus](https://github.com/facebook/jest/tree/main/packages/jest-circus) runner. +:::note + +This is only available with the default [jest-circus](https://github.com/facebook/jest/tree/main/packages/jest-circus) runner. + +::: Use `test.failing` when you are writing a test and expecting it to fail. These tests will behave the other way normal tests do. If `failing` test will throw any errors then it will pass. If it does not throw it will fail. -> Tip: You can use this type of tests i.e. when writing code in a BDD way. In that case the tests will not show up as failing until they pass. Then you can just remove the `failing` modifier to make them pass. +:::tip + +You can use this type of tests i.e. when writing code in a BDD way. In that case the tests will not show up as failing until they pass. Then you can just remove the `failing` modifier to make them pass. It can also be a nice way to contribute failing tests to a project, even if you don't know how to fix the bug. diff --git a/e2e/__tests__/__snapshots__/testFailingJasmine.test.ts.snap b/e2e/__tests__/__snapshots__/testFailingJasmine.test.ts.snap index aef1f69ab33b..661f7796996c 100644 --- a/e2e/__tests__/__snapshots__/testFailingJasmine.test.ts.snap +++ b/e2e/__tests__/__snapshots__/testFailingJasmine.test.ts.snap @@ -2,84 +2,19 @@ exports[`throws an error about unsupported modifier 1`] = ` "FAIL __tests__/statuses.test.js - ● fails + ● Test suite failed to run - expect(received).toBe(expected) // Object.is equality - - Expected: 101 - Received: 10 - - 11 | - 12 | it('fails', () => { - > 13 | expect(10).toBe(101); - | ^ - 14 | }); - 15 | - 16 | it.skip('skips', () => { - - at Object.toBe (__tests__/statuses.test.js:13:14) - - ● .add(1, 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}, - - at ../../packages/jest-each/build/bind.js:45:11 - at Array.forEach () - at Object. (__tests__/statuses.test.js:30:1) - - ● .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}, + Jest: \`failing\` tests are only supported in \`jest-circus\`. - at ../../packages/jest-each/build/bind.js:45:11 - at Array.forEach () - at Object. (__tests__/statuses.test.js:30:1) - - ● .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}, - - at ../../packages/jest-each/build/bind.js:45:11 - at Array.forEach () - at Object. (__tests__/statuses.test.js:30:1) - - ● failing passes = fails - - Failing test passed even though it was supposed to fail. Remove \`.failing\` to remove error. - - 44 | }); - 45 | - > 46 | it.failing('failing passes = fails', () => { + 20 | it.todo('todo'); + 21 | + > 22 | it.failing('failing fails = passes', () => { | ^ - 47 | expect(10).toBe(10); - 48 | }); - 49 | + 23 | expect(10).toBe(101); + 24 | }); + 25 | - at Object.failing (__tests__/statuses.test.js:46:4) + at Object.failing (__tests__/statuses.test.js:22:4) FAIL __tests__/worksWithConcurrentMode.test.js ● block with concurrent › failing test @@ -99,194 +34,75 @@ FAIL __tests__/worksWithConcurrentMode.test.js at Object.toBe (__tests__/worksWithConcurrentMode.test.js:10:16) - ● block with concurrent › failing passes = fails + ● block with concurrent › encountered a declaration exception - Failing test passed even though it was supposed to fail. Remove \`.failing\` to remove error. - - 11 | }); - 12 | - > 13 | it.concurrent.failing('failing passes = fails', () => { - | ^ - 14 | expect(10).toBe(10); - 15 | }); - 16 | - - at failing (__tests__/worksWithConcurrentMode.test.js:13:17) - at Object.describe (__tests__/worksWithConcurrentMode.test.js:8:1) - - ● block with concurrent › .add(1, 1) - - Failing test passed even though it was supposed to fail. Remove \`.failing\` to remove error. + Jest: \`failing\` tests are only supported in \`jest-circus\`. 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}, - at ../../packages/jest-each/build/bind.js:45:11 - at Array.forEach () - at __tests__/worksWithConcurrentMode.test.js:17:3 - 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}, - - at ../../packages/jest-each/build/bind.js:45:11 - at Array.forEach () - at __tests__/worksWithConcurrentMode.test.js:17:3 - 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}, - - at ../../packages/jest-each/build/bind.js:45:11 - at Array.forEach () - at __tests__/worksWithConcurrentMode.test.js:17:3 + at Function.concurrentFn.failing.each (../../packages/jest-jasmine2/build/jasmineAsyncInstall.js:207:11) + at Suite.each (__tests__/worksWithConcurrentMode.test.js:17:27) at Object.describe (__tests__/worksWithConcurrentMode.test.js:8:1) FAIL __tests__/worksWithConcurrentOnlyMode.test.js - ● block with concurrent › failing passes = fails + ● block with concurrent › skipped failing test - Failing test passed even though it was supposed to fail. Remove \`.failing\` to remove error. + expect(received).toBe(expected) // Object.is equality + Expected: 101 + Received: 10 + + 8 | describe('block with concurrent', () => { + 9 | it('skipped failing test', () => { + > 10 | expect(10).toBe(101); + | ^ 11 | }); 12 | - > 13 | it.concurrent.only.failing('failing passes = fails', () => { - | ^ - 14 | expect(10).toBe(10); - 15 | }); - 16 | + 13 | it.concurrent.only.failing('failing passes = fails', () => { - at failing (__tests__/worksWithConcurrentOnlyMode.test.js:13:22) - at Object.describe (__tests__/worksWithConcurrentOnlyMode.test.js:8:1) + at Object.toBe (__tests__/worksWithConcurrentOnlyMode.test.js:10:16) - ● block with concurrent › .add(1, 1) + ● block with concurrent › encountered a declaration exception - Failing test passed even though it was supposed to fail. Remove \`.failing\` to remove error. + Jest: \`failing\` tests are only supported in \`jest-circus\`. 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}, - at ../../packages/jest-each/build/bind.js:45:11 - at Array.forEach () - at __tests__/worksWithConcurrentOnlyMode.test.js:17:3 - 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}, - - at ../../packages/jest-each/build/bind.js:45:11 - at Array.forEach () - at __tests__/worksWithConcurrentOnlyMode.test.js:17:3 - 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}, - - at ../../packages/jest-each/build/bind.js:45:11 - at Array.forEach () - at __tests__/worksWithConcurrentOnlyMode.test.js:17:3 + at Function.concurrentFn.failing.each (../../packages/jest-jasmine2/build/jasmineAsyncInstall.js:207:11) + at Suite.each (__tests__/worksWithConcurrentOnlyMode.test.js:17:32) at Object.describe (__tests__/worksWithConcurrentOnlyMode.test.js:8:1) FAIL __tests__/worksWithOnlyMode.test.js - ● block with only, should pass › .add(1, 1) - - Failing test passed even though it was supposed to fail. Remove \`.failing\` to remove error. - - 11 | }); - 12 | - > 13 | it.only.failing.each([ - | ^ - 14 | {a: 1, b: 1, expected: 2}, - 15 | {a: 1, b: 2, expected: 3}, - 16 | {a: 2, b: 1, expected: 3}, - - at ../../packages/jest-each/build/bind.js:45:11 - at Array.forEach () - at __tests__/worksWithOnlyMode.test.js:13:3 - at Object.describe (__tests__/worksWithOnlyMode.test.js:8:1) - - ● block with only, should pass › .add(1, 2) + ● block with only, should pass › encountered a declaration exception - Failing test passed even though it was supposed to fail. Remove \`.failing\` to remove error. + Jest: \`failing\` tests are only supported in \`jest-circus\`. + 7 | + 8 | describe('block with only, should pass', () => { + > 9 | it.only.failing('failing fails = passes, should pass', () => { + | ^ + 10 | expect(10).toBe(101); 11 | }); 12 | - > 13 | it.only.failing.each([ - | ^ - 14 | {a: 1, b: 1, expected: 2}, - 15 | {a: 1, b: 2, expected: 3}, - 16 | {a: 2, b: 1, expected: 3}, - - at ../../packages/jest-each/build/bind.js:45:11 - at Array.forEach () - at __tests__/worksWithOnlyMode.test.js:13:3 - at Object.describe (__tests__/worksWithOnlyMode.test.js:8:1) - - ● block with only, should pass › .add(2, 1) - - Failing test passed even though it was supposed to fail. Remove \`.failing\` to remove error. - 11 | }); - 12 | - > 13 | it.only.failing.each([ - | ^ - 14 | {a: 1, b: 1, expected: 2}, - 15 | {a: 1, b: 2, expected: 3}, - 16 | {a: 2, b: 1, expected: 3}, - - at ../../packages/jest-each/build/bind.js:45:11 - at Array.forEach () - at __tests__/worksWithOnlyMode.test.js:13:3 + at Suite.failing (__tests__/worksWithOnlyMode.test.js:9:11) at Object.describe (__tests__/worksWithOnlyMode.test.js:8:1) - ● block with only, should fail › failing passes = fails, should fail + ● block with only, should fail › encountered a declaration exception - Failing test passed even though it was supposed to fail. Remove \`.failing\` to remove error. + Jest: \`failing\` tests are only supported in \`jest-circus\`. 29 | 30 | describe('block with only, should fail', () => { @@ -296,29 +112,27 @@ FAIL __tests__/worksWithOnlyMode.test.js 33 | }); 34 | - at failing (__tests__/worksWithOnlyMode.test.js:31:11) + at Suite.failing (__tests__/worksWithOnlyMode.test.js:31:11) at Object.describe (__tests__/worksWithOnlyMode.test.js:30:1) - ● block with only in other it, should skip › failing test + ● block with only in other it, should skip › encountered a declaration exception - expect(received).toBe(expected) // Object.is equality - - Expected: 101 - Received: 10 + Jest: \`failing\` tests are only supported in \`jest-circus\`. + 43 | + 44 | describe('block with only in other it, should skip', () => { + > 45 | it.failing('failing passes = fails, should fail but skipped', () => { + | ^ + 46 | expect(10).toBe(10); + 47 | }); 48 | - 49 | it.only('failing test', () => { - > 50 | expect(10).toBe(101); - | ^ - 51 | }); - 52 | - 53 | it('passing test but skipped', () => { - at Object.toBe (__tests__/worksWithOnlyMode.test.js:50:16) + at Suite.failing (__tests__/worksWithOnlyMode.test.js:45:6) + at Object.describe (__tests__/worksWithOnlyMode.test.js:44:1) - ● block with only with different syntax, should fail › failing passes = fails, should fail 1 + ● block with only with different syntax, should fail › encountered a declaration exception - Failing test passed even though it was supposed to fail. Remove \`.failing\` to remove error. + Jest: \`failing\` tests are only supported in \`jest-circus\`. 57 | 58 | describe('block with only with different syntax, should fail', () => { @@ -328,39 +142,37 @@ FAIL __tests__/worksWithOnlyMode.test.js 61 | }); 62 | - at failing (__tests__/worksWithOnlyMode.test.js:59:7) + at Suite.failing (__tests__/worksWithOnlyMode.test.js:59:7) at Object.describe (__tests__/worksWithOnlyMode.test.js:58:1) - ● block with only with different syntax, should fail › failing passes = fails, should fail 2 - - Failing test passed even though it was supposed to fail. Remove \`.failing\` to remove error. +FAIL __tests__/worksWithSkipMode.test.js + ● block with only, should pass › encountered a declaration exception - 61 | }); - 62 | - > 63 | test.only.failing('failing passes = fails, should fail 2', () => { - | ^ - 64 | expect(10).toBe(10); - 65 | }); - 66 | + Jest: \`failing\` tests are only supported in \`jest-circus\`. - at failing (__tests__/worksWithOnlyMode.test.js:63:13) - at Object.describe (__tests__/worksWithOnlyMode.test.js:58:1) + 7 | + 8 | describe('block with only, should pass', () => { + > 9 | it.skip.failing('skipped failing fails = passes, should pass', () => { + | ^ + 10 | expect(10).toBe(101); + 11 | }); + 12 | -FAIL __tests__/worksWithSkipMode.test.js - ● block with only, should pass › failing test + at Suite.failing (__tests__/worksWithSkipMode.test.js:9:11) + at Object.describe (__tests__/worksWithSkipMode.test.js:8:1) - expect(received).toBe(expected) // Object.is equality + ● block with only, should fail › encountered a declaration exception - Expected: 101 - Received: 10 + Jest: \`failing\` tests are only supported in \`jest-circus\`. - 20 | - 21 | it('failing test', () => { - > 22 | expect(10).toBe(101); - | ^ - 23 | }); - 24 | - 25 | it.skip('passing test', () => { + 33 | + 34 | describe('block with only, should fail', () => { + > 35 | it.skip.failing('failing passes = fails, should fail', () => { + | ^ + 36 | expect(10).toBe(10); + 37 | }); + 38 | - at Object.toBe (__tests__/worksWithSkipMode.test.js:22:16)" + at Suite.failing (__tests__/worksWithSkipMode.test.js:35:11) + at Object.describe (__tests__/worksWithSkipMode.test.js:34:1)" `; diff --git a/packages/jest-circus/src/index.ts b/packages/jest-circus/src/index.ts index ed3aab310a3d..f8f67432bfe1 100644 --- a/packages/jest-circus/src/index.ts +++ b/packages/jest-circus/src/index.ts @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -import {Circus, Global} from '@jest/types'; +import type {Circus, Global} from '@jest/types'; import {bind as bindEach} from 'jest-each'; import {ErrorWithStack, convertDescriptorToString, isPromise} from 'jest-util'; import {dispatchSync} from './state'; diff --git a/packages/jest-jasmine2/src/index.ts b/packages/jest-jasmine2/src/index.ts index 417c5262f0be..2157e12dc1de 100644 --- a/packages/jest-jasmine2/src/index.ts +++ b/packages/jest-jasmine2/src/index.ts @@ -88,6 +88,13 @@ export default async function jasmine2( ); }; + failing.each = () => { + throw new ErrorWithStack( + 'Jest: `failing` tests are only supported in `jest-circus`.', + failing.each, + ); + }; + environment.global.it.failing = failing; environment.global.fit.failing = failing; environment.global.xit.failing = failing; diff --git a/packages/jest-jasmine2/src/jasmineAsyncInstall.ts b/packages/jest-jasmine2/src/jasmineAsyncInstall.ts index c4d2a115046d..693966fded07 100644 --- a/packages/jest-jasmine2/src/jasmineAsyncInstall.ts +++ b/packages/jest-jasmine2/src/jasmineAsyncInstall.ts @@ -226,14 +226,23 @@ function makeConcurrent( return spec; }; - // each is bound after the function is made concurrent, so for now it is made noop - // eslint-disable-next-line @typescript-eslint/no-empty-function - concurrentFn.each = () => () => {}; - concurrentFn.failing = () => () => { + + const failing = () => { throw new Error( 'Jest: `failing` tests are only supported in `jest-circus`.', ); }; + + failing.each = () => { + throw new Error( + 'Jest: `failing` tests are only supported in `jest-circus`.', + ); + }; + // each is bound after the function is made concurrent, so for now it is made noop + // eslint-disable-next-line @typescript-eslint/no-empty-function + concurrentFn.each = () => () => {}; + concurrentFn.failing = failing; + return concurrentFn; } From 74e5a41536b5e3691498dc5d57e54181e5c0a2fd Mon Sep 17 00:00:00 2001 From: Yusuf Khan Date: Wed, 17 Aug 2022 20:38:19 +0530 Subject: [PATCH 06/11] feat(ts): removed optional each --- packages/jest-circus/src/index.ts | 6 +----- packages/jest-types/src/Global.ts | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/packages/jest-circus/src/index.ts b/packages/jest-circus/src/index.ts index f8f67432bfe1..cb885c6d6a5e 100644 --- a/packages/jest-circus/src/index.ts +++ b/packages/jest-circus/src/index.ts @@ -148,6 +148,7 @@ const test: Global.It = (() => { fn?: Circus.TestFn, timeout?: number, ): void => _addTest(testName, mode, concurrent, fn, failing, timeout, true); + failing.each = bindEach(failing, false); return failing; }; @@ -216,21 +217,16 @@ const test: Global.It = (() => { concurrentOnly.each = bindEach(concurrentOnly, false); only.failing = bindFailing(false, 'only'); - only.failing.each = bindEach(only.failing, false); skip.failing = bindFailing(false, 'skip'); - skip.failing.each = bindEach(skip.failing, false); test.failing = bindFailing(false); - test.failing.each = bindEach(test.failing, false); test.only = only; test.skip = skip; test.concurrent = concurrentTest; concurrentTest.only = concurrentOnly; concurrentTest.skip = skip; concurrentTest.failing = bindFailing(true); - concurrentTest.failing.each = bindEach(concurrentTest.failing, false); concurrentOnly.failing = bindFailing(true, 'only'); - concurrentOnly.failing.each = bindEach(concurrentOnly.failing, false); return test; })(); diff --git a/packages/jest-types/src/Global.ts b/packages/jest-types/src/Global.ts index bc400992216b..3203e744a6e2 100644 --- a/packages/jest-types/src/Global.ts +++ b/packages/jest-types/src/Global.ts @@ -108,7 +108,7 @@ export interface HookBase { export interface Failing { (testName: TestNameLike, fn: T, timeout?: number): void; - each?: Each; + each: Each; } export interface ItBase { From 022373809f124b4e8c3f2a7e8dfd5a24f94bfa3e Mon Sep 17 00:00:00 2001 From: Yusuf Khan Date: Wed, 17 Aug 2022 20:47:19 +0530 Subject: [PATCH 07/11] fixed(test): updated snapshots --- .../testFailingJasmine.test.ts.snap | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/e2e/__tests__/__snapshots__/testFailingJasmine.test.ts.snap b/e2e/__tests__/__snapshots__/testFailingJasmine.test.ts.snap index 661f7796996c..2a6200f91f69 100644 --- a/e2e/__tests__/__snapshots__/testFailingJasmine.test.ts.snap +++ b/e2e/__tests__/__snapshots__/testFailingJasmine.test.ts.snap @@ -38,16 +38,16 @@ FAIL __tests__/worksWithConcurrentMode.test.js Jest: \`failing\` tests are only supported in \`jest-circus\`. + 11 | }); + 12 | + > 13 | it.concurrent.failing('failing passes = fails', () => { + | ^ + 14 | expect(10).toBe(10); 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}, - - at Function.concurrentFn.failing.each (../../packages/jest-jasmine2/build/jasmineAsyncInstall.js:207:11) - at Suite.each (__tests__/worksWithConcurrentMode.test.js:17:27) + + at Function.failing (../../packages/jest-jasmine2/build/jasmineAsyncInstall.js:197:11) + at Suite.failing (__tests__/worksWithConcurrentMode.test.js:13:17) at Object.describe (__tests__/worksWithConcurrentMode.test.js:8:1) FAIL __tests__/worksWithConcurrentOnlyMode.test.js @@ -72,16 +72,16 @@ FAIL __tests__/worksWithConcurrentOnlyMode.test.js Jest: \`failing\` tests are only supported in \`jest-circus\`. + 11 | }); + 12 | + > 13 | it.concurrent.only.failing('failing passes = fails', () => { + | ^ + 14 | expect(10).toBe(10); 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}, - - at Function.concurrentFn.failing.each (../../packages/jest-jasmine2/build/jasmineAsyncInstall.js:207:11) - at Suite.each (__tests__/worksWithConcurrentOnlyMode.test.js:17:32) + + at Function.failing (../../packages/jest-jasmine2/build/jasmineAsyncInstall.js:197:11) + at Suite.failing (__tests__/worksWithConcurrentOnlyMode.test.js:13:22) at Object.describe (__tests__/worksWithConcurrentOnlyMode.test.js:8:1) FAIL __tests__/worksWithOnlyMode.test.js From 108872b7a58d5965364ea2d6d844ea125eaa6216 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Wed, 17 Aug 2022 21:52:38 +0530 Subject: [PATCH 08/11] Update docs/GlobalAPI.md Co-authored-by: Tom Mrazauskas --- docs/GlobalAPI.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/docs/GlobalAPI.md b/docs/GlobalAPI.md index 8fb7f3842a7c..1e23f7741622 100644 --- a/docs/GlobalAPI.md +++ b/docs/GlobalAPI.md @@ -765,7 +765,16 @@ test.failing('it is equal', () => { ### `test.failing.each(name, fn, timeout)` -We can also run multiple tests at once by adding `each` after `failing`. + +Also under the alias: `it.failing.each(table)(name, fn)` and `` it.failing.each`table`(name, fn) `` + +:::note + +This is only available with the default [jest-circus](https://github.com/facebook/jest/tree/main/packages/jest-circus) runner. + +::: + +You can also run multiple tests at once by adding `each` after `failing`. Example: From 03a3b31ec548deb9100ee453604eec2a665bb738 Mon Sep 17 00:00:00 2001 From: Yusuf Khan Date: Wed, 17 Aug 2022 22:36:21 +0530 Subject: [PATCH 09/11] feat(tests): added more type tests, ran prettier --- docs/GlobalAPI.md | 13 ++++++------- packages/jest-types/__typetests__/globals.test.ts | 6 ++++++ packages/jest-types/src/Global.ts | 4 ++-- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/docs/GlobalAPI.md b/docs/GlobalAPI.md index 1e23f7741622..383ce6845e98 100644 --- a/docs/GlobalAPI.md +++ b/docs/GlobalAPI.md @@ -765,7 +765,6 @@ test.failing('it is equal', () => { ### `test.failing.each(name, fn, timeout)` - Also under the alias: `it.failing.each(table)(name, fn)` and `` it.failing.each`table`(name, fn) `` :::note @@ -780,12 +779,12 @@ Example: ```js test.failing.each([ - {a: 1, b: 1, expected: 2}, - {a: 1, b: 2, expected: 3}, - {a: 2, b: 1, expected: 3}, - ])('.add($a, $b)', ({a, b, expected}) => { - expect(a + b).toBe(expected); - }); + {a: 1, b: 1, expected: 2}, + {a: 1, b: 2, expected: 3}, + {a: 2, b: 1, expected: 3}, +])('.add($a, $b)', ({a, b, expected}) => { + expect(a + b).toBe(expected); +}); ``` ### `test.only.failing(name, fn, timeout)` diff --git a/packages/jest-types/__typetests__/globals.test.ts b/packages/jest-types/__typetests__/globals.test.ts index 24fd9db72efb..61685d03a166 100644 --- a/packages/jest-types/__typetests__/globals.test.ts +++ b/packages/jest-types/__typetests__/globals.test.ts @@ -268,6 +268,7 @@ expectType(test.concurrent.failing(() => {}, asyncFn)); expectType(test.concurrent.failing(function named() {}, asyncFn)); expectType(test.concurrent.failing(class {}, asyncFn)); expectType(test.concurrent.failing(class Named {}, asyncFn)); +expectType(test.concurrent.failing.each); expectError(test.concurrent.failing(testName, fn)); @@ -275,11 +276,13 @@ expectError(test.concurrent.failing(testName, fn)); expectType(test.concurrent.only.each); expectType(test.concurrent.only.failing); +expectType(test.concurrent.only.failing.each); // test.concurrent.skip expectType(test.concurrent.skip.each); expectType(test.concurrent.skip.failing); +expectType(test.concurrent.skip.failing.each); // test.each @@ -302,6 +305,7 @@ expectType(test.failing(() => {}, fn)); expectType(test.failing(function named() {}, fn)); expectType(test.failing(class {}, fn)); expectType(test.failing(class Named {}, fn)); +expectType(test.failing.each); // test.only @@ -316,6 +320,7 @@ expectType(test.only(class Named {}, fn)); expectType(test.only.each); expectType(test.only.failing); +expectType(test.only.failing.each); // test.skip @@ -329,6 +334,7 @@ expectType(test.skip(class {}, fn)); expectType(test.skip(class Named {}, fn)); expectType(test.skip.each); +expectType(test.skip.failing.each); expectType(test.skip.failing); // test.todo diff --git a/packages/jest-types/src/Global.ts b/packages/jest-types/src/Global.ts index 3203e744a6e2..0aa451f5ea98 100644 --- a/packages/jest-types/src/Global.ts +++ b/packages/jest-types/src/Global.ts @@ -106,9 +106,9 @@ export interface HookBase { (fn: HookFn, timeout?: number): void; } -export interface Failing { +export interface Failing { (testName: TestNameLike, fn: T, timeout?: number): void; - each: Each; + each: Each; } export interface ItBase { From c854298cc81cb489d85bc6f0c2a69f212f08c120 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Wed, 17 Aug 2022 20:16:46 +0200 Subject: [PATCH 10/11] Apply suggestions from code review Co-authored-by: Tom Mrazauskas --- packages/jest-types/__typetests__/globals.test.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/jest-types/__typetests__/globals.test.ts b/packages/jest-types/__typetests__/globals.test.ts index 61685d03a166..0694a1fe0d00 100644 --- a/packages/jest-types/__typetests__/globals.test.ts +++ b/packages/jest-types/__typetests__/globals.test.ts @@ -268,6 +268,7 @@ expectType(test.concurrent.failing(() => {}, asyncFn)); expectType(test.concurrent.failing(function named() {}, asyncFn)); expectType(test.concurrent.failing(class {}, asyncFn)); expectType(test.concurrent.failing(class Named {}, asyncFn)); + expectType(test.concurrent.failing.each); expectError(test.concurrent.failing(testName, fn)); @@ -305,6 +306,7 @@ expectType(test.failing(() => {}, fn)); expectType(test.failing(function named() {}, fn)); expectType(test.failing(class {}, fn)); expectType(test.failing(class Named {}, fn)); + expectType(test.failing.each); // test.only @@ -334,8 +336,8 @@ expectType(test.skip(class {}, fn)); expectType(test.skip(class Named {}, fn)); expectType(test.skip.each); -expectType(test.skip.failing.each); expectType(test.skip.failing); +expectType(test.skip.failing.each); // test.todo From 2197308d3b5adbe43ec46e935b109509522875dc Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Wed, 17 Aug 2022 20:17:15 +0200 Subject: [PATCH 11/11] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index af1909b96358..1eaf6a8a436d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ ### Features - `[expect]` [**BREAKING**] Differentiate between `MatcherContext` `MatcherUtils` and `MatcherState` types ([#13141](https://github.com/facebook/jest/pull/13141)) -- `[jest-circus]` Add `each` for failing tests ([#13142](https://github.com/facebook/jest/pull/13142)). It adds this functionality on top of previously added `failing` feature in ([#12610](https://github.com/facebook/jest/pull/12610)). +- `[jest-circus]` Add support for `test.failing.each` ([#13142](https://github.com/facebook/jest/pull/13142)) - `[jest-config]` [**BREAKING**] Make `snapshotFormat` default to `escapeString: false` and `printBasicPrototype: false` ([#13036](https://github.com/facebook/jest/pull/13036)) - `[jest-environment-jsdom]` [**BREAKING**] Upgrade to `jsdom@20` ([#13037](https://github.com/facebook/jest/pull/13037), [#13058](https://github.com/facebook/jest/pull/13058)) - `[@jest/globals]` Add `jest.Mocked`, `jest.MockedClass`, `jest.MockedFunction` and `jest.MockedObject` utility types ([#12727](https://github.com/facebook/jest/pull/12727))