1

I'm using NodeJS (specifically the SailsJS framework), and am sending an email upon creating a user. I want to verify in a Mocha test case that creating a user sends an email.

I can include something in the JSON response that states whether an email was sent and verify it in that response, but is there a better way? Perhaps some way to intercept the email and verify it?

Nikhil
  • 91
  • 1
  • 8
  • Can you post the code where you are sending the email? – Andrew Eddie May 30 '16 at 06:55
  • I'm using [nodemailer](https://github.com/nodemailer/nodemailer). They have some usage examples in their docs. I want to test it by triggering an API call, e.g. `POST /api/sendEmail` – Nikhil May 31 '16 at 19:59
  • 1
    Ok, so in principle you will need to design your code so you can inject the mailer into your API, and then you can use https://www.npmjs.com/package/nodemailer-mock-transport. If you post the code where you are sending the actual mail, I can show you how to either write a test for it, or refactor your code so that you can write a test for it. – Andrew Eddie May 31 '16 at 23:40

0 Answers0