nodemailer-mock
Advanced tools
Comparing version 1.3.3 to 1.3.4
{ | ||
"name": "nodemailer-mock", | ||
"version": "1.3.3", | ||
"version": "1.3.4", | ||
"description": "Mock nodemailer module for testing", | ||
@@ -45,3 +45,3 @@ "main": "nodemailer-mock.js", | ||
"depcheck": "^0.6.7", | ||
"eslint": "^4.2.0", | ||
"eslint": "^4.3.0", | ||
"eslint-config-google": "^0.9.1", | ||
@@ -51,3 +51,3 @@ "eslint-plugin-mocha": "^4.11.0", | ||
"istanbul-cobertura-badger": "https://github.com/doublesharp/istanbul-cobertura-badger.git", | ||
"mocha": "^3.4.2", | ||
"mocha": "^3.5.0", | ||
"should": "^11.2.1", | ||
@@ -54,0 +54,0 @@ "sloc": "^0.2.0", |
@@ -16,2 +16,3 @@ # nodemailer-mock | ||
``` | ||
@@ -21,2 +22,6 @@ npm install nodemailer-mock --save-dev | ||
``` | ||
yarn add nodemailer-mock | ||
``` | ||
# mock api | ||
@@ -48,9 +53,9 @@ There are some special methods available on the mocked module to help with testing. | ||
``` | ||
'use strict' | ||
const nodemailerMock = require('nodemailer-mock'); | ||
const transport = nodemailerMock.createTransport(); | ||
// send an email | ||
const email = //... the email you want to send | ||
// the email you want to send | ||
const email = ... // <-- your email here | ||
// send an email with nodestyle callback | ||
transport.sendMail(email, function(err, info) { | ||
@@ -64,4 +69,13 @@ if (err) { | ||
// 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){ | ||
transport.verify(function(err, success) { | ||
if (err) { | ||
@@ -76,7 +90,7 @@ console.log('Error!', err); | ||
# example using mocha and mockery | ||
Here is an example of using a mocked `nodemailer` class in a `mocha` test using `mockery` | ||
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. | ||
``` | ||
'use strict' | ||
const should = require('should'); | ||
@@ -102,5 +116,10 @@ const mockery = require('mockery'); | ||
// IMPORTANT! | ||
/* | ||
################## | ||
### IMPORTANT! ### | ||
################## | ||
*/ | ||
/* Make sure anything that uses nodemailer is loaded here, | ||
after it is mocked... */ | ||
after it is mocked just above... */ | ||
}); | ||
@@ -121,3 +140,3 @@ | ||
// call a service that uses nodemailer | ||
var response = ... // <-- your code here | ||
var response = ... // <-- your email code here | ||
@@ -124,0 +143,0 @@ // a fake test for something on our response |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
79815
180