Wednesday, 19 April 2017

node.js mock sendmailer transporter inside function

Im working with an node handler in AWS lambda and i need to make another files with integration tests from that function, but i cant mock the transporter with sinon or mockery.

the handler function:

var nodemailer = require('nodemailer');

exports.handler = (event, context, callback) =>
{
var transporter=createTransporter();
}

function createTransporter() {
return nodemailer.createTransport({
    service: "SMTp",
    auth: {
        user: "XXXX@XXX",
        pass: "XXXX"
    }
});
}

the purpose is to mock the function createTransporter() so that it doesnt send any email when it is called in javascript file test with mocha and expect.



via Daniel

No comments:

Post a Comment