DEV Community

Discussion on: Improving Angular tests by enabling Angular testing module teardown

Collapse
 
literalpie profile image
Benjamin Kindle

Hi, I'm curious if there are known, measurable benefits of using the teardown option for someone who is using Jest. Because it causes onDestroy to be called, I would expect it to reduce memory leaks (every time we unsubscribe in the onDestroy hook), but in my testing, I don't see any noticeable difference in memory use in our project with 1754 total tests.

Collapse
 
layzee profile image
Lars Gyrup Brink Nielsen

This update is about two things:

  • Performance issues when using Karma. Impact will vary.
  • Correctness. Destroying modules and services using the any or root provider scopes.

Do you have stateful Angular modules or root/any-provided services? Do they implement OnDestroy? Otherwise, you won't notice anything performance-wise. If you do, you might catch subtle bugs and you might notice performance improvements. Jest is good at parallelizing so much less so than Karma.