林與AWS拉姆達的節點處理工作模擬sendmailer轉運,我需要與從功能集成測試的另一個文件,但我不能嘲笑與興農或嘲弄的轉運。Node.js的內部功能
的index.js功能:
var nodemailer = require('nodemailer');
exports.handler = (event, context, callback) =>
{
var transporter=createTransporter();
transporter.sendMail(data, function (error, success) {
console.log(error);
response = getResponse(404, error);
}
callback(null, response);
});
}
function createTransporter() {
return nodemailer.createTransport({
service: "SMTP",
auth: {
user: "[email protected]",
pass: "XXXX"
}
});
}
目的是嘲笑功能createTransporter(),因此它不發送的電子郵件時,它被稱爲在JavaScript文件測試與摩卡和期待:
var mockery = require('mockery');
var nodemailerMock = require('nodemailer-mock');
var index = require("../index.js");
describe("The handler function tests", function() {
before(function() {
mockery.enable({
warnOnUnregistered: false
});
mockery.registerMock('nodemailer', nodemailerMock);
});
it('JSON error html ', function() {
var callback = function (name, response) {
expect(JSON.stringify(response.statusCode)).to.be('404');
};
var context = {};
index.handler(event, context, callback);
});
});
你看https://github.com/doublesharp/nodemailer-mock? –
我沒有,但也許我做錯了什麼 – acknowledge101