From 556b320e26be8f5ba7ce0a2ab5c7c8e9532ef603 Mon Sep 17 00:00:00 2001 From: dealerweb Date: Thu, 13 Aug 2026 10:23:12 +0200 Subject: [PATCH] test: serve a fresh mock response per fetch in the keep-alive test The keep-alive test parked one shared Response instance in mockResolvedValue, but a Response body is single-use - as soon as more than one request lands in the 30s window the second read dies with "Body is unusable" and the ping reports a lost connection. Serve a fresh Response per call via mockImplementation, the pattern the rest of this file already uses. --- lib/__tests__/jmap-client-resilience.test.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/__tests__/jmap-client-resilience.test.ts b/lib/__tests__/jmap-client-resilience.test.ts index 8d9f907ef..caf674320 100644 --- a/lib/__tests__/jmap-client-resilience.test.ts +++ b/lib/__tests__/jmap-client-resilience.test.ts @@ -373,7 +373,10 @@ describe('JMAPClient resilience', () => { client.onConnectionChange(callback); const echoResponse = { methodResponses: [['Core/echo', { ping: 'pong' }, '0']] }; - fetchSpy.mockResolvedValue(mockFetchResponse(200, echoResponse)); + // A Response body is single-use, so one shared instance breaks as soon + // as anything fetches more than once in the window - serve a fresh one + // per call like the other tests in this file. + fetchSpy.mockImplementation(() => Promise.resolve(mockFetchResponse(200, echoResponse))); // Advance past keep-alive interval (30s) await vi.advanceTimersByTimeAsync(30_000);