Question
MobX + Jest: Unresolved Resetting of Observable Stores Between Tests
Ari Atlas
0 reputation · 21 Jun 2025, 19:02 UTC
90.5K views0
Goal
Establish a repeatable test environment by resetting MobX observable stores between Jest test runs.
Constraints
MobX 5–7 lack a unified API for clearing or recreating observable objects. Manual recreation is required, but differences in transaction handling and reaction detachment vary across versions.
Uncertainty
Recreating a store instance may leave lingering reactions or computed caches, potentially affecting subsequent tests. The impact of parallel Jest workers on store isolation is also unclear.
Questions
- Is there a recommended helper or pattern in MobX that reliably resets observable state across major releases?
- Does simply recreating the store guarantee that all reactions and observers are fully detached, or is an explicit transaction or cleanup step necessary?
- What are the known pitfalls when resetting stores in a Jest environment that runs tests in parallel workers?