From 5800de8d343649bb4c93ca31c61911879123c736 Mon Sep 17 00:00:00 2001 From: Denis Badurina Date: Mon, 8 Feb 2021 19:27:44 +0100 Subject: [PATCH] fix(client): Should emit `closed` event when disposing Closes #108 --- src/client.ts | 8 -------- src/tests/client.ts | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/client.ts b/src/client.ts index e87d1ad2..1ac156fc 100644 --- a/src/client.ts +++ b/src/client.ts @@ -258,13 +258,6 @@ export function createClient(options: ClientOptions): Client { listener(...args); } }, - reset() { - (Object.keys(listeners) as (keyof typeof listeners)[]).forEach( - (event) => { - listeners[event] = []; - }, - ); - }, }; })(); @@ -554,7 +547,6 @@ export function createClient(options: ClientOptions): Client { const socket = await connecting; socket.close(1000, 'Normal Closure'); } - emitter.reset(); }, }; } diff --git a/src/tests/client.ts b/src/tests/client.ts index 3f235695..ea9f8d7a 100644 --- a/src/tests/client.ts +++ b/src/tests/client.ts @@ -1029,4 +1029,22 @@ describe('events', () => { expect(cal[0]).toHaveProperty('wasClean'); }); }); + + it('should emit closed event when disposing', async (done) => { + const { url, waitForClient } = await startTServer(); + + const client = createClient({ + url, + lazy: false, + retryAttempts: 0, + onNonLazyError: noop, + on: { + closed: () => done(), + }, + }); + + await waitForClient(); + + client.dispose(); + }); });