在这里,我想断言回调函数是否被调用。那么我该如何使用 sinon js 来做到这一点。请建议。
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);
}
};
我试过如下:
var mailjetClient = require('../../node_modules/node-mailjet/mailjet-client');
sinon.stub(mailjet, 'post').withArgs('send').returns(mailjetClient);
sinon.stub(mailjetClient, 'request').returns(Promise);
我收到以下错误:
TypeError: Attempted to wrap undefined property request as function