-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mqtt.connect giving error in Jest: Jest has detected the following 1 open handle potentially keeping Jest from exiting #1482
Comments
i had the same problem. this issue got me thinking and i tried something. i got a successful close of the mqtt client by adding a waiting period (mine was 3 seconds) export const mqttShutdown = () => {
return new Promise<void>((resolve) =>
client.end(true, {}, () => {
setTimeout(() => {
resolve();
}, 3000);
}),
);
}; so i guess in your case that will become: (below code is untested, just quickly written to try to translate my approach to your callback-based and multi-client approach) cleanup(doneCallback) {
Promise.all(
this.clients.map((client) => {
return new Promise((resolve) => {
if (client.connected) {
client.end(true, {}, () => {
setTimeout(resolve, 3000);
});
} else {
resolve();
}
});
});
)
.then(() => {
doneCallback();
});
} and then use plugin.cleanup(done) do note that i added and since by default you can't have more than 5s for a hook in jest this is useful... |
is this for integration tests? |
can you provide a sample test with jest? |
Anyone that would like to try |
does it make sense to expose https://github.com/mqttjs/MQTT.js/blob/main/test/server_helpers_for_client_tests.js |
Follow: #1641 |
MQTT 5.0.0 BETA is now available! Try it out and give us feedback: |
I have a test for a class that revolves around MQTT:
MQTTHMIPlugin.ts
MQTTHMIPlugin.spec.ts
Even though I'm calling
cleanup()
in 3 different places and callingdone
, Jest still thinks there's an open handle and refuses to exit:How can I have Jest exit properly, without using
--forceExit
?The text was updated successfully, but these errors were encountered: