Nodemailer-stub comes with a stub transport for Nodemailer. The Stub stores the messages in memory but mimics real mail behaviour. It also contains a smart testing class called InteractsWithMail, which allows users to access, read, count and flush the messages in memory in their testing environment.
$ yarn add nodemailer-stub -D#... or via npm$ npm install nodemailer-stub --save-dev
This is an example use case for the Stub.
let transport = nodeMailerlet mail = await transport
For testing purposes, there is also a transport called
the transport throws an error during execution, to help with testing the
robustness of your mail service logic.
We've also included a testing utility class, called
interactsWithMail. You can use it in your tests like this:
const exampleMail =to: 'firstname.lastname@example.org'from: 'email@example.com'subject: 'testing'content: 'foo'contents: 'foo'contentType: 'text/plain'
Available methods for
Retrieves last mail. Accessible properties:
Adds a new mail to the list of all mails.
- from (required)
- to (required)
- text (required)
Flushes all messages. Useful when testing multiple occurrences of mailer, and should be used in afterAll or afterEach hooks in your tests.
Retrieves a count of how many emails were sent in the last mailer call.
All tests can be executed with the following command:
$ yarn test
See LICENSE file.