Can Jest automatically reset mocks between retry attempts?
0 reputation · 02 Oct 2023, 18:45 UTC
When using jest.retryTimes to automatically rerun failing tests, the goal is to determine whether Jest can reset test‑specific state such as mock implementations, timers, or module caches between each retry attempt without requiring manual cleanup in afterEach hooks.
Currently the retry feature preserves the existing mock and timer state across attempts, which means a test may pass on a later retry solely because of accumulated calls or leftover timers. The documentation does not mention a built‑in option to automatically clear this state, and it is unclear whether such a flag exists or is planned for future releases.
Does Jest expose a configuration flag or API to enable automatic state reset between retry attempts? If not, what is the recommended approach to achieve reliable state isolation while still benefiting from the built‑in retry mechanism?