Your original method is not really very testable, as you can't really verify when it completed execution.
To that end, you might want to rewrite the method with the following signature, adding a done
callback.
Mail.prototype.send = function(config, opts, done) {
var transport;
// server connect options
config = { ... };
// mail body options
opts = { ... };
transport = nodemailer.createTransport("SMTP", config);
transport.sendMail(opts, done);
};
Your test could then create an spy and pass that as the done
callback, and assert the spy function has been called exactly once.