From ee1db565719598b3840bc5b10e95d84d4f8b07b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Warda?= Date: Tue, 26 Apr 2022 19:14:35 +0200 Subject: [PATCH] Add missing specs for skipping with only --- .../__snapshots__/testFailing.test.ts.snap | 77 +++++-------------- .../__tests__/worksWithOnlyMode.test.js | 23 +++++- packages/jest-circus/src/eventHandler.ts | 10 ++- 3 files changed, 46 insertions(+), 64 deletions(-) diff --git a/e2e/__tests__/__snapshots__/testFailing.test.ts.snap b/e2e/__tests__/__snapshots__/testFailing.test.ts.snap index 271aee186a03..9d7a021649db 100644 --- a/e2e/__tests__/__snapshots__/testFailing.test.ts.snap +++ b/e2e/__tests__/__snapshots__/testFailing.test.ts.snap @@ -1,81 +1,40 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`works with all statuses 1`] = ` -"FAIL __tests__/statuses.test.js - ✓ passes - ✕ fails - ✓ failing failes = passes - ✕ failing passes = fails - ○ skipped skips - ○ skipped skipped failing 1 - ○ skipped skipped failing 2 - ✎ todo todo - - ● fails - - 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) - - ● failing passes = fails - - Failing test passed even though it was supposed to fail. Remove \`.failing\` to remove error." -`; - exports[`works with only mode 1`] = ` "FAIL __tests__/worksWithOnlyMode.test.js block with only, should pass ✓ failing failes = passes, should pass - ○ skipped failing test - ○ skipped passing test + ○ skipped failing test but skipped + ○ skipped passing test but skipped block with only, should fail ✕ failing passes = fails, should fail - ○ skipped failing test - ○ skipped passing test + ○ skipped failing test but skipped + ○ skipped passing test but skipped + block with only in other it, should skip + ✕ failing test + ○ skipped failing passes = fails, should fail but skipped + ○ skipped passing test but skipped ● 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." -`; + Failing test passed even though it was supposed to fail. Remove \`.failing\` to remove error. + -exports[`works with skip mode 1`] = ` -"FAIL __tests__/worksWithSkipMode.test.js - block with only, should pass - ✕ failing test - ✓ failing failes = passes - ○ skipped skipped failing failes = passes, should pass - ○ skipped passing test - block with only, should fail - ✓ passing test - ✓ failing passes = fails - ○ skipped failing passes = fails, should fail - ○ skipped failing test - ● block with only, should pass › failing test + ● block with only in other it, should skip › failing test expect(received).toBe(expected) // Object.is equality Expected: 101 Received: 10 - 12 | - 13 | it('failing test', () => { - > 14 | expect(10).toBe(101); + 41 | // eslint-disable-next-line jest/no-focused-tests + 42 | it.only('failing test', () => { + > 43 | expect(10).toBe(101); | ^ - 15 | }); - 16 | - 17 | it.skip('passing test', () => { + 44 | }); + 45 | + 46 | it('passing test but skipped', () => { - at Object.toBe (__tests__/worksWithSkipMode.test.js:14:16)" + at Object.toBe (__tests__/worksWithOnlyMode.test.js:43:16)" `; diff --git a/e2e/test-failing/__tests__/worksWithOnlyMode.test.js b/e2e/test-failing/__tests__/worksWithOnlyMode.test.js index adfb5b43521d..4ae2057d83c6 100644 --- a/e2e/test-failing/__tests__/worksWithOnlyMode.test.js +++ b/e2e/test-failing/__tests__/worksWithOnlyMode.test.js @@ -10,11 +10,11 @@ describe('block with only, should pass', () => { expect(10).toBe(101); }); - it('failing test', () => { + it('failing test but skipped', () => { expect(10).toBe(101); }); - it('passing test', () => { + it('passing test but skipped', () => { expect(10).toBe(10); }); }); @@ -24,11 +24,26 @@ describe('block with only, should fail', () => { expect(10).toBe(10); }); - it('failing test', () => { + it('failing test but skipped', () => { expect(10).toBe(101); }); - it('passing test', () => { + it('passing test but skipped', () => { + expect(10).toBe(10); + }); +}); + +describe('block with only in other it, should skip', () => { + it.failing('failing passes = fails, should fail but skipped', () => { + expect(10).toBe(10); + }); + + // eslint-disable-next-line jest/no-focused-tests + it.only('failing test', () => { + expect(10).toBe(101); + }); + + it('passing test but skipped', () => { expect(10).toBe(10); }); }); diff --git a/packages/jest-circus/src/eventHandler.ts b/packages/jest-circus/src/eventHandler.ts index 38aee07a563e..904ebd383d7a 100644 --- a/packages/jest-circus/src/eventHandler.ts +++ b/packages/jest-circus/src/eventHandler.ts @@ -122,7 +122,15 @@ const eventHandler: Circus.EventHandler = (event, state) => { } case 'add_test': { const {currentDescribeBlock, currentlyRunningTest, hasStarted} = state; - const {asyncError, fn, mode, testName: name, timeout, concurrent, failing} = event; + const { + asyncError, + fn, + mode, + testName: name, + timeout, + concurrent, + failing, + } = event; if (currentlyRunningTest) { currentlyRunningTest.errors.push(