Skip to content

Commit

Permalink
fix(client): Should emit closed event when disposing
Browse files Browse the repository at this point in the history
Closes #108
  • Loading branch information
enisdenjo committed Feb 8, 2021
1 parent cd12024 commit 5800de8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
8 changes: 0 additions & 8 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,6 @@ export function createClient(options: ClientOptions): Client {
listener(...args);
}
},
reset() {
(Object.keys(listeners) as (keyof typeof listeners)[]).forEach(
(event) => {
listeners[event] = [];
},
);
},
};
})();

Expand Down Expand Up @@ -554,7 +547,6 @@ export function createClient(options: ClientOptions): Client {
const socket = await connecting;
socket.close(1000, 'Normal Closure');
}
emitter.reset();
},
};
}
Expand Down
18 changes: 18 additions & 0 deletions src/tests/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});

0 comments on commit 5800de8

Please sign in to comment.