Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
darrachequesne committed Mar 14, 2024
1 parent 5060b82 commit 9632bfc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -687,10 +687,12 @@ export class Socket<
);
if (!isBuffered) {
// note: handlers that do not accept an error as first argument are ignored here
if (this.acks[id].withError) {
this.acks[id].call(this, new Error("socket has been disconnected"));
}
const ack = this.acks[id];
delete this.acks[id];

if (ack.withError) {
ack.call(this, new Error("socket has been disconnected"));
}
}
});
}
Expand Down
7 changes: 7 additions & 0 deletions test/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,9 @@ describe("socket", () => {

socket.disconnect();

// @ts-ignore property 'acks' is private
expect(Object.keys(socket.acks).length).to.eql(0);

setTimeout(() => success(done, socket), 100);
});
});
Expand All @@ -693,6 +696,9 @@ describe("socket", () => {
socket.timeout(10_000).emit("echo", "a", (err) => {
expect(err).to.be.an(Error);

// @ts-ignore property 'acks' is private
expect(Object.keys(socket.acks).length).to.eql(0);

success(done, socket);
});

Expand Down Expand Up @@ -768,6 +774,7 @@ describe("socket", () => {
socket.once("connect", () => {
socket.disconnect();

// the packet will be buffered and sent upon reconnection
socket.emit("echo", "a", (value) => {
expect(value).to.eql("a");

Expand Down

0 comments on commit 9632bfc

Please sign in to comment.