fix(tests): deflake recipe modal resource item tests by disposing modal instances

RecipeModal instances keep fire-and-forget async chains (hydration
re-renders, mark-hash-invalid re-renders, 500ms reconnect/restore
re-renders) and deferred DOM wiring timers alive across tests. On slow
CI runners these land in the next test's window and overwrite or re-wire
the shared document.body with stale content and stale instance handlers,
failing a different test on every run.

Add a tracked-timer helper and a dispose() teardown hook to RecipeModal:
pending deferred work is cancelled, in-flight async chains become no-ops
after disposal, and the global click listener is detached. The test
afterEach now disposes every modal instance, making the file hermetic.
This commit is contained in:
Will Miao
2026-09-02 12:40:37 +08:00
parent b37238d790
commit 6b41c3bbb4
2 changed files with 81 additions and 13 deletions
@@ -210,7 +210,11 @@ describe('RecipeModal resource item interactions', () => {
});
afterEach(() => {
createdModals.forEach(recipeModal => recipeModal.cleanupNavigationShortcuts());
// dispose() marks each modal instance dead: pending deferred timers
// (wiring, 500ms reconnect re-renders) are cancelled and in-flight
// async chains become no-ops, so nothing from this test can touch the
// DOM of the next one.
createdModals.forEach(recipeModal => recipeModal.dispose());
createdModals.length = 0;
document.body.innerHTML = '';
delete global.modalManager;