Thursday, 11 October 2018

Why can't I properly stub the twilio library with sinon?

In my code, I have:

function handleMessage() {
  const twilio = require('twilio')(process.env.TWILIO_ACCOUNT_SID, process.env.TWILIO_AUTH_TOKEN);
  let recordings = twilio.recordings(foundConference.RecordingSid);
  console.log('recordings', recordings);
  return recordings.remove();
}

And in my stub, I have:

const sinon = require('sinon');
const twilio = require('twilio')(process.env.TWILIO_ACCOUNT_SID, process.env.TWILIO_AUTH_TOKEN);

exports.twilioRecordings = () => {
  console.log('about to stub', twilio.recordings);
  sinon.stub(twilio, 'recordings').returns('here');
  console.log('finished stub', twilio.recordings);

  return;
};

However, it doesn't actually create a stubbed function. It's still using the original recordings function. What am I doing wrong?



from Why can't I properly stub the twilio library with sinon?

No comments:

Post a Comment