Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

beforeAll is fired even when not in the current describe.only context #8614

Closed
pixelastic opened this issue Jun 27, 2019 · 2 comments
Closed

Comments

@pixelastic
Copy link
Contributor

pixelastic commented Jun 27, 2019

🐛 Bug Report

When a test file has several describe() contexts, and one of them if focused using describe.only(), beforeAll() methods in all other contexts are still fired, even if no tests of those contexts are actually run.

This seems similar to #8379, but this time regarding .only() and not .skip().

To Reproduce

The following test file exhibits the issue:

describe('context', () => {
  describe.only('foo', () => {
    it('should work', () => {
      expect(true).toEqual(true);
    });
  });
  describe('bar', () => {
    beforeAll(() => {
      console.info("[beforeAll]: this should not appear");
    });
    beforeEach(() => {
      console.info("[beforeEach]: this should not appear");
    });
    it('should not be run', () => {
      expect(true).toEqual(true);
    });
  });
});

Output:
image

Expected behavior

None of the console.log should be called. The correct behavior of the beforeEach should also be applied to beforeAll.

Link to repl or repo (highly encouraged)

Live demo or repo to clone.

Run npx envinfo --preset jest

  System:
    OS: Linux 4.15 Ubuntu 18.04.2 LTS (Bionic Beaver)
    CPU: (4) x64 Intel(R) Core(TM) i7-7600U CPU @ 2.80GHz
  Binaries:
    Node: 10.11.0 - ~/.nvm/versions/node/v10.11.0/bin/node
    Yarn: 1.16.0 - ~/.yarn/bin/yarn
    npm: 6.4.1 - ~/.nvm/versions/node/v10.11.0/bin/npm
  npmPackages:
    jest: 24.8.0 => 24.8.0
@pixelastic pixelastic changed the title beforeAll is fired even not in the current describe.only context beforeAll is fired even when not in the current describe.only context Jun 27, 2019
@pixelastic
Copy link
Contributor Author

This has been fixed in Jest 27. I'm closing this. Thanks a lot!

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant