diff --git a/packages/socket.io/test/socket-timeout.ts b/packages/socket.io/test/socket-timeout.ts index 62f36807b8..8d520eb168 100644 --- a/packages/socket.io/test/socket-timeout.ts +++ b/packages/socket.io/test/socket-timeout.ts @@ -84,4 +84,40 @@ describe("timeout", () => { success(done, io, client); }); }); + it("should timeout if the client disconnects before acknowledging the event", (done) => { + const io = new Server(0); + const client = createClient(io, "/"); + + client.on("echo", () => { + client.disconnect(); + }); + + io.on("connection", (socket) => { + socket.timeout(50).emit("echo", (err) => { + expect(err).to.be.an(Error); + expect(socket.connected).to.be(false); + success(done, io, client); + }); + }); + }); + + it("should timeout if the client disconnects before acknowledging the event (promise)", (done) => { + const io = new Server(0); + const client = createClient(io, "/"); + + client.on("echo", () => { + client.disconnect(); + }); + + io.on("connection", async (socket) => { + try { + await socket.timeout(50).emitWithAck("echo"); + expect().fail(); + } catch (err) { + expect(err).to.be.an(Error); + expect(socket.connected).to.be(false); + success(done, io, client); + } + }); + }); });