Custom Jest environment that detects async leaks between tests, enforces test isolation, and prevents flaky failures in CI.
npm install jest-doctor   
jest-doctor is a custom Jest environment that detects async leaks within tests and fails flaky tests deterministically.
Out-of-the-box jest-doctor supports node and jsdom environments.
Add one of the environments to your Jest config:
``js``
export default {
testEnvironment: "jest-doctor/env/node",
// optional
reporters: ["default", "jest-doctor/reporter"],
};
Run your tests as usual and jest-doctor will report leaks such as unresolved promises or timers.
Full documentation, configuration and more:
š https://stephan-dum.github.io/jest-doctor/
---
If jest-doctor helped you eliminate flaky tests, consider ā starring the repo.
