dwyl / sendemail

💌 Simplifies reliably sending emails from your node.js apps using AWS Simple Email Service (SES)
181 stars 26 forks source link

Being able to stub out the sendemail module #55

Closed samhstn closed 7 years ago

samhstn commented 7 years ago

When testing functions/endpoints that use sendemail, I would like to be able to stub out the sendemail function to avoid sending an actual email every time I run my tests (it slows down tests and fills up inboxes).

Libraries like sinon follow the pattern of sinon.stub(module, 'methodToStub').

This module currently doesn't facilitate this pattern.

Would you consider changing the api to something like:

email.send('welcome', person, function (error, result) {

instead of:

email('welcome', person, function(error, result){

I'm happy to do this if you don't mind the api change

nelsonic commented 7 years ago

@shouston3 thank you for creating this issue/question! 😻 We have a little experience using Sinon in aws-sdk-mock it might be worth checking if this object-based method calling will work with Sinon before changing the API.

could you do the following:

var email = require('sendemail').email;

email('welcome', person, function (error, result) {
// etc
}

BTW: I'm 100% "On Board" with adding the default method to be the email one if that simplifies things but we ideally shouldn't "break" backward compatibility for existing users of the module... 😉

samhstn commented 7 years ago

As far as I'm aware, you would only be able to overwrite methods of a required in object, not a required in function.