diff --git a/CHANGELOG.md b/CHANGELOG.md index 8052d1334837..d1494a2c5b29 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ ### Fixes +- `[jest-jasmine2]` Don't run `beforeAll` / `afterAll` in skipped describe block + ### Chore & Maintenance ### Performance diff --git a/e2e/skip-before-after-all/__tests__/skipDescribe.test.js b/e2e/skip-before-after-all/__tests__/skipDescribe.test.js new file mode 100644 index 000000000000..f25f4f4eb80b --- /dev/null +++ b/e2e/skip-before-after-all/__tests__/skipDescribe.test.js @@ -0,0 +1,32 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ +let hasBeforeAllRun = false; +let hasAfterAllRun = false; + +describe.skip('in describe.skip', () => { + describe('in describe', () => { + beforeAll(() => { + hasBeforeAllRun = true; + }); + + afterAll(() => { + hasAfterAllRun = true; + }); + + test('it should be skipped', () => { + global.fail(); + }); + }); +}); + +test('in describe.skip beforeAll should not run', () => { + expect(hasBeforeAllRun).toBe(false); +}); + +test('in describe.skip afterAll should not run', () => { + expect(hasAfterAllRun).toBe(false); +}); diff --git a/e2e/skip-before-after-all/package.json b/e2e/skip-before-after-all/package.json new file mode 100644 index 000000000000..148788b25446 --- /dev/null +++ b/e2e/skip-before-after-all/package.json @@ -0,0 +1,5 @@ +{ + "jest": { + "testEnvironment": "node" + } +} diff --git a/packages/jest-jasmine2/src/treeProcessor.ts b/packages/jest-jasmine2/src/treeProcessor.ts index 5bd4eeebe255..607b12936344 100644 --- a/packages/jest-jasmine2/src/treeProcessor.ts +++ b/packages/jest-jasmine2/src/treeProcessor.ts @@ -23,7 +23,7 @@ export type TreeNode = { onException: (error: Error) => void; sharedUserContext: () => any; children?: Array; -} & Pick; +} & Pick; export default function treeProcessor(options: Options): void { const { @@ -78,7 +78,7 @@ export default function treeProcessor(options: Options): void { const children = node.children.map(child => ({ fn: getNodeHandler(child, enabled), })); - if (!hasEnabledTest(node)) { + if (!hasEnabledTest(node) || node.markedPending) { return children; } return node.beforeAllFns.concat(children).concat(node.afterAllFns);