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.
This commit is contained in:
dealerweb
2026-08-13 11:57:38 +02:00
parent 70383dea18
commit 556b320e26
+4 -1
View File
@@ -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);