From bcfae0434b07d0b34fa90add45308b9a9b33ddda Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sat, 21 Feb 2026 23:26:04 +0000 Subject: [PATCH] test(fetch): table-drive sync throw cleanup coverage --- src/infra/fetch.test.ts | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/src/infra/fetch.test.ts b/src/infra/fetch.test.ts index 0a81b5259..fb01f27de 100644 --- a/src/infra/fetch.test.ts +++ b/src/infra/fetch.test.ts @@ -111,21 +111,6 @@ describe("wrapFetchWithAbortSignal", () => { } }); - it("cleans up listener and rethrows when fetch throws synchronously", () => { - const syncError = new TypeError("sync fetch failure"); - const fetchImpl = withFetchPreconnect( - vi.fn(() => { - throw syncError; - }), - ); - const wrapped = wrapFetchWithAbortSignal(fetchImpl); - - const { fakeSignal, removeEventListener } = createForeignSignalHarness(); - - expect(() => wrapped("https://example.com", { signal: fakeSignal })).toThrow(syncError); - expect(removeEventListener).toHaveBeenCalledOnce(); - }); - it("preserves original rejection when listener cleanup throws", async () => { const fetchError = new TypeError("fetch failed"); const cleanupError = new TypeError("cleanup failed"); @@ -140,9 +125,17 @@ describe("wrapFetchWithAbortSignal", () => { expect(removeEventListener).toHaveBeenCalledOnce(); }); - it("preserves original sync throw when listener cleanup throws", () => { + it.each([ + { + name: "cleans up listener and rethrows when fetch throws synchronously", + makeSignalHarness: () => createForeignSignalHarness(), + }, + { + name: "preserves original sync throw when listener cleanup throws", + makeSignalHarness: () => createThrowingCleanupSignalHarness(new TypeError("cleanup failed")), + }, + ])("$name", ({ makeSignalHarness }) => { const syncError = new TypeError("sync fetch failure"); - const cleanupError = new TypeError("cleanup failed"); const fetchImpl = withFetchPreconnect( vi.fn(() => { throw syncError; @@ -150,7 +143,7 @@ describe("wrapFetchWithAbortSignal", () => { ); const wrapped = wrapFetchWithAbortSignal(fetchImpl); - const { fakeSignal, removeEventListener } = createThrowingCleanupSignalHarness(cleanupError); + const { fakeSignal, removeEventListener } = makeSignalHarness(); expect(() => wrapped("https://example.com", { signal: fakeSignal })).toThrow(syncError); expect(removeEventListener).toHaveBeenCalledOnce();