mailgun / mailgun-js-boland

A simple Node.js helper module for Mailgun API.
http://bojand.github.io/mailgun-js
MIT License
894 stars 122 forks source link

How to throw an error in test mode #263

Open danbergelt opened 4 years ago

danbergelt commented 4 years ago

1) What version of the module is the issue happening on? Does the issue happen on latest version?

0.22.0

2) What platform and Node.js version? (For example Node.js 6.9.1 on Mac OS X)

Node.JS 12, Mac OS X

3) Does the action work when you manually perform request against mailgun using curl (or other means)?

No

4) Sample source code or steps to reproduce

I am attempting to run integration tests against an API controller which sends an email, and am having trouble figuring out if there is a way to force an email sent in test mode to throw. I have the below try/catch block:

    try {
      return await sendForgotPasswordEmail(body.email, link, res);
    } catch (_) {
      return catchForgotPasswordEmail(user, next);
    }

which handles the case when the sent email throws, but according to the documentation:

Note that in test mode no error or body are returned as a result.

Is there a way to reliably test a failed request without actually sending an email?