Search code examples
node.jsjestjssendgrid

Jest mock sendgrid send email


I use sendGrid email in my nodejs app

https://github.com/sendgrid/sendgrid-nodejs/tree/master/packages/mail

And basically, when user signs up, I will send a welcome email

But when I write test for user sign up, I want to mock sendgrid send function. How can I do it with jest. Or any suggestion on how can I test the signup api


Solution

  • You can use sendgrid's sandbox mode to avoid emails actually being sent