title: How to handle RabbitMQ Connection on Node.js to use on Jest?
body: <p>I have a below code snippet to connect RabbitMQ, Its working fine but in test case, I am getting an <em>asynchronous operations</em> error. I tried using <code>this.start();</code> and also <code>this.start().then</code></p>
  
  <pre><code>var amqplib = require('amqplib');
  const { amqp: { uri: amqpURI } } = require('../config');
  
  class Broker {
      constructor(url) {
          this.queue = 'user';
          this.url = url;
          //this.start(); Old
          this.start().then(function (conn) {
              console.log(conn);
          });
      }
      start() {
          return amqplib.connect(this.url).then((conn) =&gt; {
              conn.on("close", () =&gt; {
                  this.conn = null;
                  return this.retryConnection();
              });
              return conn;
          }).catch((error) =&gt; {
          });
      }
  
      .....
  
  }
  </code></pre>
  
  <p><em>Note : When I comment <code>this.start();</code> the error disappear</em></p>
  
  <p><strong>Error :</strong></p>
  
  <blockquote>
    <p><strong>Jest did not exit one second after the test run has completed.</strong></p>
    
    <p>This usually means that there are asynchronous operations that weren't
    stopped in your tests. Consider running Jest with
    <code>--detectOpenHandles</code> to troubleshoot this issue.</p>
  </blockquote>