From 5df16db967709dcf574b117d24c1a89f8309850f Mon Sep 17 00:00:00 2001 From: Jan Romann Date: Mon, 4 Dec 2023 23:33:50 +0100 Subject: [PATCH] test(mqtt): make use of broker server more type-safe --- .../mqtt-client-subscribe-test.integration.ts | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/packages/binding-mqtt/test/mqtt-client-subscribe-test.integration.ts b/packages/binding-mqtt/test/mqtt-client-subscribe-test.integration.ts index f03b5abd1..26cd32be5 100644 --- a/packages/binding-mqtt/test/mqtt-client-subscribe-test.integration.ts +++ b/packages/binding-mqtt/test/mqtt-client-subscribe-test.integration.ts @@ -31,7 +31,7 @@ should(); describe("MQTT client implementation", () => { let servient: Servient; - let brokerServer: MqttBrokerServer; + let brokerServer: MqttBrokerServer | undefined; const brokerAddress = "localhost"; const brokerPort = 1889; @@ -43,7 +43,7 @@ describe("MQTT client implementation", () => { afterEach(async () => { await servient.shutdown(); - await brokerServer.stop(); + await brokerServer?.stop(); }); it("should expose via broker", function (done: Mocha.Done) { @@ -53,14 +53,11 @@ describe("MQTT client implementation", () => { this.skip(); } - brokerServer = new MqttBrokerServer({ uri: brokerUri, selfHost: true }); - servient.addServer(brokerServer); - servient.addClientFactory(new MqttClientFactory()); servient.start().then((WoT) => { - expect(brokerServer.getPort()).to.equal(brokerPort); - expect(brokerServer.getAddress()).to.equal(brokerAddress); + expect(brokerServer?.getPort()).to.equal(brokerPort); + expect(brokerServer?.getAddress()).to.equal(brokerAddress); const eventNumber = Math.floor(Math.random() * 1000000); const eventName: string = "event" + eventNumber; @@ -121,8 +118,8 @@ describe("MQTT client implementation", () => { servient.addClientFactory(new MqttsClientFactory({ rejectUnauthorized: false })); servient.start().then((WoT) => { - expect(brokerServer.getPort()).to.equal(brokerPort); - expect(brokerServer.getAddress()).to.equal(brokerAddress); + expect(brokerServer?.getPort()).to.equal(brokerPort); + expect(brokerServer?.getAddress()).to.equal(brokerAddress); const eventNumber = Math.floor(Math.random() * 1000000); const eventName: string = "event" + eventNumber;