From e47ee79241346018aafe69a381d2822ef75ae873 Mon Sep 17 00:00:00 2001 From: amanape <83104063+amanape@users.noreply.github.com> Date: Tue, 9 Dec 2025 16:32:00 +0400 Subject: [PATCH] fix(frontend): add WebSocket client cleanup and delay between tests --- frontend/__tests__/hooks/use-websocket.test.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/frontend/__tests__/hooks/use-websocket.test.ts b/frontend/__tests__/hooks/use-websocket.test.ts index 4a1be2403a..45b934f442 100644 --- a/frontend/__tests__/hooks/use-websocket.test.ts +++ b/frontend/__tests__/hooks/use-websocket.test.ts @@ -32,9 +32,17 @@ describe("useWebSocket", () => { }); // Clean up after each test to prevent cross-test contamination - afterEach(() => { + afterEach(async () => { // Unmount any rendered hooks to trigger their cleanup effects (closes WebSocket connections) cleanup(); + // Clear all tracked WebSocket clients to prevent cross-test message leaks + // This is necessary because wsLink is a singleton and clients persist across tests + wsLink.clients.forEach((client) => client.close()); + wsLink.clients.clear(); + // Small delay to ensure WebSocket cleanup completes before next test starts + await new Promise((resolve) => { + setTimeout(resolve, 10); + }); }); it("should establish a WebSocket connection", async () => {