Skip to content

Instantly share code, notes, and snippets.

@aj07mm
Last active August 29, 2015 14:16
Show Gist options
  • Save aj07mm/036acc6da39f432774bf to your computer and use it in GitHub Desktop.
Save aj07mm/036acc6da39f432774bf to your computer and use it in GitHub Desktop.
how to test response in a callback inside a method inside a method?
'sendMail': function(mailBody,maiSubject,mailTo, sendAt){
if(mailTo == 'string'){
mailTo = formatMailTo(mailTo);
}
var message = {
"html": mailBody,
"text": mailBody,
"subject": maiSubject,
"from_email": "[email protected]",
"from_name": "foobarsatanico",
"to": mailTo
};
Mandrill.messages.send({"message": message, "async": false, "send_at": sendAt }, function(result) {
console.log(result);
return result;
}, function(e) {
console.log('A mandrill error occurred: ' + e.name + ' - ' + e.message);
return e.message;
});
}
@rdiego26
Copy link

Inject a callback an return result.

sendMail: function(mailBody,maiSubject,mailTo, sendAt, callback) {

    if(mailTo == 'string'){
        mailTo = formatMailTo(mailTo);
    }

    var message = {
        "html": mailBody,
        "text": mailBody,
        "subject": maiSubject,
        "from_email": "[email protected]",
        "from_name": "foobarsatanico",
        "to": mailTo
    };

    Mandrill.messages.send({"message": message, "async": false, "send_at": sendAt }, function(result) {
        console.log(result);
        callback(result);
    }, function(e) {
        console.log('A mandrill error occurred: ' + e.name + ' - ' + e.message);
        callback(e.message);
    });
}

OR use Promise. 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment