My function is sendMail i want to stub function mailjet and it has a method chain mailjet.post('send').request...
I want to assert callback is called on mail success or fail.
So how i stub this method chain?
var sendMail = function (templateName, callback) {
// From template name find template id of mailjet
mailingExternalTemplateModel.findMailingTemplateId(templateName, function (err, result) {
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 done
sinon.stub(mailjet, 'post').withArgs('send').returns(mailjetClient);
sinon.stub(mailjetClient, 'request').returns(Promise);
But i got error TypeError: Attempted to wrap undefined property request as function