![Create React App Officially Deprecated Amid React 19 Compatibility Issues](https://cdn.sanity.io/images/cgdhsj6q/production/04fa08cf844d798abc0e1a6391c129363cc7e2ab-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Create React App Officially Deprecated Amid React 19 Compatibility Issues
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
@eclass/nodemailer-mock
Advanced tools
Mocked nodemailer module for unit testing.
npm install @eclass/nodemailer-mock --save-dev
yarn add -D @eclass/nodemailer-mock
There are some special methods available on the mocked module to help with testing.
nodemailerMock.mock.reset()
nodemailerMock.mock.sentMail()
nodemailerMock.mock.shouldFailOnce()
transport.sendMail()
nodemailerMock.mock.shouldFail(true|false)
transport.sendMail()
true
, return errorfalse
, return successnodemailerMock.mock.mockedVerify(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.successResponse(success)
transport.sendMail()
nodemailerMock.mock.failResponse(err)
transport.sendMail()
The mocked module behaves in a similar fashion to other transports provided by nodemailer
.
const nodemailerMock = require('@eclass/nodemailer-mock');
const transport = nodemailerMock.createTransport();
// the email you want to send
const email = ... // <-- your email here
// send an email with nodestyle callback
transport.sendMail(email, function(err, info) {
if (err) {
console.log('Error!', err, info);
} else {
console.log('Success!', info);
}
}
// send an email with promises
transport.sendMail(email)
.then(function(info) {
console.log('Success!', info);
})
.catch(function(err) {
console.log('Error!', err);
});
// verify a transport
transport.verify(function(err, success) {
if (err) {
console.log('Error!', err);
} else {
console.log('Success!', success);
}
})
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.
const should = require('should');
const mockery = require('mockery');
const nodemailerMock = require('@eclass/nodemailer-mock');
describe('Tests that send email', function() {
/* This could be an app, Express, etc. It should be
instantiated *after* nodemailer is mocked. */
let app = null;
before(function() {
// 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(function() {
// Reset the mock back to the defaults after each test
nodemailerMock.mock.reset();
});
after(function() {
// Remove our mocked nodemailer and disable mockery
mockery.deregisterAll();
mockery.disable();
});
it('should send an email using nodemailer-mock', function(done) {
// call a service that uses nodemailer
var 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.sentMail();
// we should have sent one email
sentMail.length.should.be.exactly(1);
// check the email for something
sentMail[0].property.should.be.exactly('foobar');
done();
});
it('should fail to send an email using nodemailer-mock', function(done) {
// tell the mock class to return an error
const err = 'My custom error';
nodemailerMock.mock.shouldFailOnce();
nodemailerMock.mock.failResponse(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);
done();
});
it('should verify using the real nodemailer transport', function(done) {
// tell the mock class to pass verify requests to nodemailer
nodemailerMock.mock.mockedVerify(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 */
done();
});
});
FAQs
Mock nodemailer module for testing
The npm package @eclass/nodemailer-mock receives a total of 1 weekly downloads. As such, @eclass/nodemailer-mock popularity was classified as not popular.
We found that @eclass/nodemailer-mock demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.