Skip to content

Commit

Permalink
fix: don't run beforeAll/afterAll in skipped block
Browse files Browse the repository at this point in the history
  • Loading branch information
jeiea committed Apr 30, 2020
1 parent ad1b9dc commit 4487796
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

### Fixes

- `[jest-jasmine2]` Don't run `beforeAll` / `afterAll` in skipped describe block

### Chore & Maintenance

### Performance
Expand Down
32 changes: 32 additions & 0 deletions e2e/skip-before-after-all/__tests__/skipDescribe.test.js
Original file line number Diff line number Diff line change
@@ -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);
});
5 changes: 5 additions & 0 deletions e2e/skip-before-after-all/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"jest": {
"testEnvironment": "node"
}
}
4 changes: 2 additions & 2 deletions packages/jest-jasmine2/src/treeProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export type TreeNode = {
onException: (error: Error) => void;
sharedUserContext: () => any;
children?: Array<TreeNode>;
} & Pick<Suite, 'getResult' | 'parentSuite' | 'result'>;
} & Pick<Suite, 'getResult' | 'parentSuite' | 'result' | 'markedPending'>;

export default function treeProcessor(options: Options): void {
const {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 4487796

Please sign in to comment.