Comments (5)
@popod @Darkripper214 I made an update to make the module more compatible with jest
- the passthrough of the transport.verify()
is not possible as the module is mocked before the mock module loads. In version 1.5.5+ it checks to see if nodemailer
is available and bypasses it if not - make sure to use this version with jest
tests.
I also included some examples for both jest
and mocha
in the README and source code in ./examples/
. For jest
, it would look something like the following:
/**
* Jest Mock
* ./__mocks__/nodemailer.js
**/
module.exports = require('nodemailer-mock');
/**
* Jest Test
* ./__tests__/my-test.js
**/
const { mock } = require('nodemailer');
test('Send an email using the mocked nodemailer', async () => {
/* ... run your tests that send emails here */
// check the mock for our sent emails
const sentEmails = mock.getSentMail();
// there should be one
expect(sentEmails.length).toBe(1);
// and it should match the to address
expect(sentEmails[0].to).toBe('[email protected]');
});
Let me know if you have any issues, thanks!
from nodemailer-mock.
@Darkripper214 I figured out how to do it... you will need to update to [email protected]+
to use the .getMockFor()
method which will allow you to pass in the real nodemailer
when the mock is loaded.
/**
* Jest Mock
* ./__mocks__/nodemailer.js
**/
// load the real nodemailer
const nodemailer = require('nodemailer');
// pass it in when creating the mock using getMockFor()
const nodemailerMock = require('nodemailer-mock').getMockFor(nodemailer);
// export the mocked module
module.exports = nodemailerMock;
from nodemailer-mock.
I'm exploring using this library with jest. Would be more than happy to assist to update the document if the maintainer is interested. Let me know!
from nodemailer-mock.
@Darkripper214 That would be great! I just don't have time to work on it right now but would be happy to update the documentation if you get it working. Thanks!
from nodemailer-mock.
@doublesharp I was going to do update this weekend. Basically everything works fine for jest
except for the transport.verify()
due to the way mocking works.
I was going to ask if it is necessary to provide user ability to use the actual instance to do the transport.verify()
in a test scenario?
from nodemailer-mock.
Related Issues (9)
- Node 4 requires flag without 'use strict' HOT 1
- Mock rejected emails HOT 2
- Cannot set property 'mailer' of undefined HOT 3
- Unwanted developer tools install HOT 2
- TemplateSender support. HOT 4
- Installing nodemailer-mock changes package.json, git hooks and adds bunch of files to root folder HOT 1
- Add support for sendMail()'s Promise return value HOT 3
- The presence of npm-shrinkwrap.json making shrink wrapping fail at the root module HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nodemailer-mock.