Skip to content

Commit 9fa7858

Browse files
test: add reject-path coverage for abort listener cleanup
Verifies .finally() runs removeEventListener when the request rejects (via timeout), not just on resolve. Adapted from #1672's test suite.
1 parent 214e8a0 commit 9fa7858

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

packages/core/test/shared/protocol.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,23 @@ describe('protocol tests', () => {
288288
expect(removeSpy).toHaveBeenCalledTimes(5);
289289
});
290290

291+
test('should remove abort listener when request rejects', async () => {
292+
await protocol.connect(transport);
293+
294+
const controller = new AbortController();
295+
const removeSpy = vi.spyOn(controller.signal, 'removeEventListener');
296+
297+
const mockSchema = z.object({ result: z.string() });
298+
await expect(
299+
testRequest(protocol, { method: 'example', params: {} }, mockSchema, {
300+
signal: controller.signal,
301+
timeout: 0
302+
})
303+
).rejects.toThrow();
304+
305+
expect(removeSpy).toHaveBeenCalledWith('abort', expect.any(Function));
306+
});
307+
291308
test('should not overwrite existing hooks when connecting transports', async () => {
292309
const oncloseMock = vi.fn();
293310
const onerrorMock = vi.fn();

0 commit comments

Comments
 (0)