title: rabbitMQ unit tests with amqplib-mocks library
body: <p>I am trying to write unit tests with <a href="https://github.com/Bunk/amqplib-mocks" rel="nofollow noreferrer">amqplib-mocks</a> but i can not consume message from consumer, i am getting undefined and i try to debug but not successfull.</p>
  
  <pre><code>describe("Rabbitmq testing Server", () =&gt; {
      let connection, channel;
  
      before(async () =&gt; {
          connection = await amqplib.connect("amqp://localhost");
          channel = await connection.createChannel();
  
          await channel.assertExchange(messagesExchange, exchangeType);
  
          isCreated = await channel.assertQueue(queue);
          isCreated.queue ? console.log('queue created') : 'Queue not created or already exist';
  
          await channel.bindQueue(queue, messagesExchange, routingKey);
  
          const isPublish = channel.publish(messagesExchange, routingKey, Buffer.from('should pass test')).valueOf();
          isPublish ? console.log('message published successfully') : 'message not published';
      });
  
      it("should create the channel", () =&gt; {
          assert.isObject(channel);
      });
  
      it("should register the method call", () =&gt; {
          expect(connection.createChannel()).to.have.been.all.keys;
          expect(connection.createChannel()).to.have.been.all.members;
      });
  
      it("should consumer consume message from queue", async () =&gt; {
          let result: string;
          const consumer = await channel.consume(queue, (msg) =&gt; {
              result = msg.content.toString();
              console.log(result);
          }, { noAck: true });
  
          // expect(result).to.be.equal(JSON.stringify({ success: true }));
      });
  
      after(() =&gt; {
          amqplib.reset();
      })
  </code></pre>
  
  <p>first two tests are passing but third test getting undefined value. Any help would be appreciate.</p>