diff --git a/test/namespaces.ts b/test/namespaces.ts index d78d25f86d..ffe9602c30 100644 --- a/test/namespaces.ts +++ b/test/namespaces.ts @@ -6,6 +6,7 @@ import { createClient, successFn, createPartialDone, + assert, } from "./support/util"; describe("namespaces", () => { @@ -417,6 +418,7 @@ describe("namespaces", () => { socket1.on("a", successFn(done, io, socket1, socket2)); socket2.on("connect", () => { + assert(socket2.id); io.except(socket2.id).emit("a"); }); }); @@ -435,6 +437,7 @@ describe("namespaces", () => { socket1.on("a", successFn(done, io, socket1, socket2)); socket2.on("connect", () => { + assert(socket2.id); nsp.except(socket2.id).emit("a"); }); }); diff --git a/test/support/util.ts b/test/support/util.ts index ac78016fbe..1742010f48 100644 --- a/test/support/util.ts +++ b/test/support/util.ts @@ -63,6 +63,16 @@ export function successFn( return () => success(done, sio, ...clientSockets); } +/** + * Asserts a condition so that typescript will recognize the assertion! + * + * Uses expect's `ok` check on condition + * @param condition + */ +export function assert(condition: any): asserts condition { + expect(condition).to.be.ok(); +} + export function getPort(io: Server): number { // @ts-ignore return io.httpServer.address().port; diff --git a/test/uws.ts b/test/uws.ts index 13ede296af..3a287e6468 100644 --- a/test/uws.ts +++ b/test/uws.ts @@ -7,6 +7,7 @@ import { Server } from ".."; import { io as ioc, Socket as ClientSocket } from "socket.io-client"; import request from "supertest"; import expect from "expect.js"; +import { assert } from "./support/util"; const createPartialDone = (done: (err?: Error) => void, count: number) => { let i = 0; @@ -134,6 +135,8 @@ describe("socket.io with uWebSocket.js-based engine", () => { clientWSOnly.on("hello", partialDone); clientPollingOnly.on("hello", partialDone); clientCustomNamespace.on("hello", shouldNotHappen(done)); + assert(clientWSOnly.id); + assert(clientPollingOnly.id); io.of("/").sockets.get(clientWSOnly.id)!.join("room1"); io.of("/").sockets.get(clientPollingOnly.id)!.join("room1"); @@ -148,6 +151,8 @@ describe("socket.io with uWebSocket.js-based engine", () => { clientWSOnly.on("hello", partialDone); clientPollingOnly.on("hello", partialDone); clientCustomNamespace.on("hello", shouldNotHappen(done)); + assert(clientWSOnly.id); + assert(clientPollingOnly.id); io.of("/").sockets.get(clientWSOnly.id)!.join("room1"); io.of("/").sockets.get(clientPollingOnly.id)!.join("room2"); @@ -163,6 +168,8 @@ describe("socket.io with uWebSocket.js-based engine", () => { clientPollingOnly.on("hello", shouldNotHappen(done)); clientCustomNamespace.on("hello", shouldNotHappen(done)); + assert(clientWSOnly.id); + assert(clientPollingOnly.id); io.of("/").sockets.get(clientWSOnly.id)!.join("room1"); io.of("/").sockets.get(clientPollingOnly.id)!.join("room2"); @@ -177,6 +184,9 @@ describe("socket.io with uWebSocket.js-based engine", () => { clientPollingOnly.on("hello", partialDone); clientCustomNamespace.on("hello", shouldNotHappen(done)); + assert(client.id); + assert(clientWSOnly.id); + assert(clientPollingOnly.id); io.of("/").sockets.get(client.id)!.join("room1"); io.of("/").sockets.get(clientPollingOnly.id)!.join("room1"); @@ -189,6 +199,7 @@ describe("socket.io with uWebSocket.js-based engine", () => { it("should not crash when socket is disconnected before the upgrade", (done) => { client.on("disconnect", () => done()); + assert(client.id); io.of("/").sockets.get(client.id)!.disconnect(); });