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

afterAll is not invoked when tested code has syntax error #2698

Closed
dirkmc opened this issue Jan 25, 2017 · 4 comments
Closed

afterAll is not invoked when tested code has syntax error #2698

dirkmc opened this issue Jan 25, 2017 · 4 comments

Comments

@dirkmc
Copy link

dirkmc commented Jan 25, 2017

I am using jest to test my node server code. As I make changes to the code I run the tests. If there is a syntax error in my code jest helpfully points me to the line. The problem is that when there is a syntax error, jest invokes beforeAll but not afterAll. I'm using beforeAll to create a database and set up mocks, and afterAll to drop this database, so when there are syntax errors and afterAll is not invoked, it leaves around databases that I then have to clean up manually.

I'd like jest to always either

  • not invoke either beforeAll or afterAll
  • invoke both beforeAll or afterAll
@thymikee
Copy link
Collaborator

I'm not sure if there's an easy way to do it right now, but we should definitely investigate into handling such cases (if possible)

@cpojer
Copy link
Member

cpojer commented Jan 25, 2017

Can you provide a repro, @dirkmc.

@dirkmc
Copy link
Author

dirkmc commented Jan 26, 2017

I'm sorry, after further testing I realized that afterAll is being called. I'll close the ticket.

@dirkmc dirkmc closed this as completed Jan 26, 2017
@dirkmc
Copy link
Author

dirkmc commented Jan 26, 2017

After doing further testing I've identified the root cause, which is that when beforeAll throws an exception or returns a promise that rejects, the tests are still run. I've opened an issue here:
#2713

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants