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

[jest-circus] throw if beforeAll or afterAll hooks defined in empty describe block #6293

Closed
aaronabramov opened this issue May 26, 2018 · 4 comments · Fixed by #6320
Closed

Comments

@aaronabramov
Copy link
Contributor

aaronabramov commented May 26, 2018

right now Jasmine would run beforeAll and afterAll hooks even if there are no tests. e.g.

beforeAll(() => console.log('1');
afterAll(() => console.log('2');
test.skip('test', () => {});

will print

>1
>2
// ...
describe('something', () => {
  beforeAll(() => console.log(1);
  afterAll(() => console.log('2');
  // no `test` or `it` in this describe
});

will do the same.

because there's no point in doing so we should disallow it and throw an error

the fix should be inside jest-circus package
to run jest tests using jest-circus run JEST_CIRCUS=1 ./jest

@captbaritone
Copy link
Contributor

I'm looking at this.

@aaronabramov
Copy link
Contributor Author

sweet! let's reuse unhandledErrors state key for that, so the test still runs, but later fails the suite

@aaronabramov
Copy link
Contributor Author

(see errors in afterAll hook implementation)

captbaritone added a commit to captbaritone/jest that referenced this issue May 27, 2018
captbaritone added a commit to captbaritone/jest that referenced this issue May 27, 2018
captbaritone added a commit to captbaritone/jest that referenced this issue May 28, 2018
cpojer pushed a commit that referenced this issue May 30, 2018
* [Jest Circus] Make hooks in empty describe blocks error

Fixes #6293

* Prettier

* Trim stack trace for hooks in empty describe blocks

* Document hooks in empty describe blocks in CHANGELOG.md

* Move to e2e

* Add missing snapshots

* Improve error message

* Add test asserting we can have hooks in blocks with skipped tests
@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 May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants