question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Automatically cleanup if afterEach is detected

See original GitHub issue

Right now, users need to call afterEach(cleanup) or configure Jest to do so. This makes sure test run in isolation, but requires manual action.


As React Testing Library just did, we should probably automatically call cleanup if afterEach method exists.

RTL ended up offering two opt-out mechanisms (via custom import or using an env variable), but I’m not sure this is totally needed. I would keep the env variable (VTL_SKIP_AUTO_CLEANUP), but still have a single import point (instead of creating that “pure” version on VTL). Not a big deal, though.

So a PR (or several PRs) should:

  • Automatically call afterEach(cleanup) if afterEach exists.
  • Add an opt-out mechanism by using VTL_SKIP_AUTO_CLEANUP.
  • Add tests asserting the behavior outlined above.
  • Remove cleanup references from tests and docs.
  • Replace cleanup-after-each with a warning (reference).
  • State that the change is a breaking change (so that we take it into account when merging!).

After that, we’d need to update the official docs.

I’m marking this as a good first issue since details are outlined and the referenced PR from RTL makes a great starting point 😃

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
afontcucommented, Aug 19, 2019

🎉 This issue has been resolved in version 3.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

1reaction
Oluwasetemicommented, Aug 10, 2019

Can I jump on this

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why we need `afterEach(cleanup);`? - Stack Overflow
Hi. I started using @nrwl/react these days. This is amazing products and I'm excited monorepos project with nx. Btw, there is afterEach(cleanup); ...
Read more >
Setup - Testing Library
Cleanup is called after each test automatically by default if the testing framework you're using supports the afterEach global (like mocha, ...
Read more >
Common mistakes with React Testing Library - Kent C. Dodds
If you'd like to avoid several of these common mistakes, ... For a long time now cleanup happens automatically (supported for most major ......
Read more >
USB port may stop working after you remove or insert a USB ...
To fix this problem, use the following methods in the order in which they are listed. After each method, check the USB device...
Read more >
Remove unwanted ads, pop-ups & malware - Android
Tip: To remember the apps that you remove so that you can add them back, make a list. After each removal, restart your...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found