Here, I want to assert that callback function is called or not. So how can I do it using sinon js. Please suggest.
var send = function (templateId, callback) {
const request = mailjet
.post("send")
.request(params)
request
.then((result) => {
if (typeof callback === 'function') {
callback(null, result.body);
}
})
.catch((err) => {
if (typeof callback === 'function') {
callback(err, null);
}
})
} else {
callback(err, null);
}
};
I have tried as following:
var mailjetClient = require('../../node_modules/node-mailjet/mailjet-client');
sinon.stub(mailjet, 'post').withArgs('send').returns(mailjetClient);
sinon.stub(mailjetClient, 'request').returns(Promise);
I am getting following error:
TypeError: Attempted to wrap undefined property request as function