HiveMQ MQTT Module¶
This module allows automatic start up of HiveMQ's docker container within test suites, to enable programmatic testing of JavaScript based MQTT client applications.
Install¶
npm install @testcontainers/hivemq --save-dev
Resources¶
Please make sure to check out the hivemq-docs for the Community Edition.
Info
We are working to support the HiveMQ Enterprise Edition as outlined in the Java Test Containers Module.
Examples¶
it("should connect to HiveMQ Community Edition via MQTT.js", async () => {
const container = await new HiveMQContainer(IMAGE).start();
const testMqttClient = mqtt.connect(container.getConnectionString());
const promise = new Promise<void>((resolve) => {
testMqttClient.on("message", (topic, message) => {
expect(message.toString()).toEqual("Test Message");
testMqttClient.end();
resolve();
});
});
testMqttClient.on("connect", () => {
testMqttClient.subscribe("test", (error) => {
if (!error) {
testMqttClient.publish("test", "Test Message");
}
});
});
return expect(promise).resolves.toBeUndefined();
});