我的函数是 sendMail 我想存根函数 mailjet,它有一个方法链 mailjet.post('send').request...
我想断言在邮件成功或失败时调用回调。
那么我如何存根这个方法链呢?
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);
}
});};
我已经做好了
sinon.stub(mailjet, 'post').withArgs('send').returns(mailjetClient);
sinon.stub(mailjetClient, 'request').returns(Promise);
但我收到错误 TypeError: Attempted to wrap undefined property request as function