对于以下代码片段,如果它属于 file ,nodejs
我将如何使用and对send
方法进行存根?我尝试了很多方法,但不断出错。proxyquire
sinon
index.js
var emailjs = require("emailjs");
emailjs.server.connect({
user: obj.user,
password: obj.password,
host: obj.host,
port: obj.port,
tls: obj.tls,
ssl: obj.ssl
})
.send(mailOptions, function(error, message){
if (error) {
console.log("ERROR");
context.done(new Error("There was an error sending the email: %s", error));
return;
} else {
console.log("SENT");
context.done();
return;
}
});
到目前为止,在我的测试中,我有以下设置,但是得到Uncaught TypeError: Property 'connect' of object #<Object> is not a function
.
readFileStub = sinon.stub();
sendStub = sinon.stub();
connectStub = sinon.stub().returns(sendStub);
testedModule = proxyquire('../index', {
'fs': {readFile: readFileStub},
'emailjs': {
'server': {
'connect': {
'send': sendStub
}
}
}
});