0

Could you please help me understand below code? I am not able mock method using sinon, what could be wrong with it?

const amqplib = require('amqplib');

async function getMessage() {
  const x = amqlib.connect({});
}

// Daemon process
getMessage();

module.exports = {
  getMessage,
};

mocking code as:

const mqConnMock = sinon.stub(amqplib, 'connect');
ssc-hrep3
  • 15,024
  • 7
  • 48
  • 87
  • An async function returns a resolving promise when there is no method body. – ssc-hrep3 Dec 03 '19 at 14:47
  • To be precise ..I am having nodejs code looks like like below. const amqplib = require('amqplib'); async function getMessage() { const x = amqlib.connect({}); } // Daemon process getMessage(); module.exports = { getMessage, } mocking code as : const mqConnMock = sinon.stub(amqplib, 'connect'); Mock is not working this case. when i remove line 8 mocking works fine. Could you please help me fix this? – kishor kumar Dec 03 '19 at 15:28
  • Does this help? https://stackoverflow.com/a/46227268/3233827 – ssc-hrep3 Dec 03 '19 at 20:56
  • No, it didn't. I tired but with no luck. – kishor kumar Dec 04 '19 at 08:06

1 Answers1

0
module.exports.getMessage = async function getMessage() {
  (...)
}
David
  • 1,084
  • 12
  • 36