Gathering detailed insights and metrics for nodemailer-mock-pooled
Gathering detailed insights and metrics for nodemailer-mock-pooled
Gathering detailed insights and metrics for nodemailer-mock-pooled
Gathering detailed insights and metrics for nodemailer-mock-pooled
npm install nodemailer-mock-pooled
Typescript
Module System
Node Version
NPM Version
69.7
Supply Chain
99.4
Quality
74.9
Maintenance
50
Vulnerability
100
License
JavaScript (98.46%)
Shell (1.37%)
HTML (0.17%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
78 Commits
1 Branches
1 Contributors
Updated on May 24, 2019
Latest Version
1.5.1
Package Id
nodemailer-mock-pooled@1.5.1
Unpacked Size
149.11 kB
Size
52.93 kB
File Count
17
NPM Version
6.4.1
Node Version
10.15.3
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
Mocked nodemailer module for unit testing.
npm install nodemailer-mock-pooled --save-dev
yarn add -D nodemailer-mock-pooled
There are some special methods available on the mocked module to help with testing. They are under the .mock
key of the mocked nodemailer
.
nodemailerMock.mock.reset()
nodemailerMock.mock.getSentMail()
nodemailerMock.mock.setShouldFailOnce()
transport.sendMail()
nodemailerMock.mock.setShouldFail(true|false)
transport.sendMail()
true
, return errorfalse
, return successnodemailerMock.mock.setMockedVerify(true|false)
transport.verify()
should be mocked or passed through to nodemailer
true
, use a mocked callbackfalse
, pass through to a real nodemailer
transportnodemailerMock.mock.setSuccessResponse(success)
transport.sendMail()
nodemailerMock.mock.setFailResponse(err)
transport.sendMail()
nodemailerMock.mock.setIdle(true|false)
nodemailerMock.mock.setShouldIdle(true|false)
transport.sendMail()
Note that the
.mock
methods in previous versions are aliased to the new names.
The mocked module behaves in a similar fashion to other transports provided by nodemailer
.
setup test
const nodemailerMock = require('nodemailer-mock-pooled');
const transport = nodemailerMock.createTransport();
// the email you want to send
const email = ... // <-- your email here
use nodestyle callbacks
// send with nodestyle callback
transport.sendMail(email, function(err, info) {
if (err) {
return console.log('Error!', err, info);
}
return console.log('Success!', info);
}
// verify with nodestyle callback
transport.verify(function(err, success) {
if (err) {
return console.log('Error!', err);
}
return console.log('Success!', success);
});
use promises
// send with promises
transport.sendMail(email)
.then(function(info) {
console.log('Success!', info);
})
.catch(function(err) {
console.log('Error!', err);
});
// verify with promises
transport.verify()
.then(function(success) {
console.log('Success!', success);
});
.catch(function(err) {
console.log('Error!', err);
});
use async/await
// send an email with async / wait
try {
const info = await transport.sendMail(email);
} catch (err) {
console.log('Error!', err);
}
// verify with async / wait
try {
const info = await transport.verify();
} catch (err) {
console.log('Error!', err);
}
Here is an example of using a mocked nodemailer
class in a mocha
test using mockery
. Make sure that any modules that require()
's a mocked module must be called AFTER the module is mocked or node will use the unmocked version from the module cache. Note that this example uses async/await
. See the module tests for additional example code.
const should = require('should');
const mockery = require('mockery');
const nodemailerMock = require('nodemailer-mock-pooled');
describe('Tests that send email', async () {
/* This could be an app, Express, etc. It should be
instantiated *after* nodemailer is mocked. */
let app = null;
before(async () {
// Enable mockery to mock objects
mockery.enable({
warnOnUnregistered: false,
});
/* Once mocked, any code that calls require('nodemailer')
will get our nodemailerMock */
mockery.registerMock('nodemailer', nodemailerMock)
/*
##################
### IMPORTANT! ###
##################
*/
/* Make sure anything that uses nodemailer is loaded here,
after it is mocked just above... */
});
afterEach(async () {
// Reset the mock back to the defaults after each test
nodemailerMock.mock.reset();
});
after(async () {
// Remove our mocked nodemailer and disable mockery
mockery.deregisterAll();
mockery.disable();
});
it('should send an email using nodemailer-mock-pooled', async () {
// call a service that uses nodemailer
const response = ... // <-- your email code here
// a fake test for something on our response
response.value.should.be.exactly('value');
// get the array of emails we sent
const sentMail = nodemailerMock.mock.getSentMail();
// we should have sent one email
sentMail.length.should.be.exactly(1);
// check the email for something
sentMail[0].property.should.be.exactly('foobar');
});
it('should fail to send an email using nodemailer-mock-pooled', async () {
// tell the mock class to return an error
const err = 'My custom error';
nodemailerMock.mock.setShouldFailOnce();
nodemailerMock.mock.setFailResponse(err);
// call a service that uses nodemailer
var response = ... // <-- your code here
// a fake test for something on our response
response.error.should.be.exactly(err);
});
it('should verify using the real nodemailer transport', async () {
// tell the mock class to pass verify requests to nodemailer
nodemailerMock.mock.setMockedVerify(false);
// call a service that uses nodemailer
var response = ... // <-- your code here
/* calls to transport.verify() will be passed through,
transport.sendMail() is still mocked */
});
});
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
no SAST tool detected
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
41 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-14
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More