nodemailer-mock
Advanced tools
Comparing version 1.3.1 to 1.3.2
{ | ||
"name": "nodemailer-mock", | ||
"version": "1.3.1", | ||
"version": "1.3.2", | ||
"description": "Mock nodemailer module for testing", | ||
@@ -45,7 +45,7 @@ "main": "nodemailer-mock.js", | ||
"depcheck": "^0.6.7", | ||
"eslint": "^3.19.0", | ||
"eslint": "^4.1.1", | ||
"eslint-config-google": "^0.8.0", | ||
"eslint-plugin-mocha": "^4.9.0", | ||
"eslint-plugin-mocha": "^4.11.0", | ||
"istanbul": "^0.4.5", | ||
"istanbul-cobertura-badger": "^1.3.0", | ||
"istanbul-cobertura-badger": "https://github.com/doublesharp/istanbul-cobertura-badger.git", | ||
"mocha": "^3.4.2", | ||
@@ -52,0 +52,0 @@ "should": "^11.2.1", |
111
README.md
@@ -48,12 +48,12 @@ # nodemailer-mock | ||
const nodemailerMock = require('nodemailer-mock') | ||
const transport = nodemailerMock.createTransport() | ||
const nodemailerMock = require('nodemailer-mock'); | ||
const transport = nodemailerMock.createTransport(); | ||
// send an email | ||
const email = //... the email you want to send | ||
transport.sendMail(email, function(err, info){ | ||
if (err){ | ||
console.log('Error!', err, info) | ||
transport.sendMail(email, function(err, info) { | ||
if (err) { | ||
console.log('Error!', err, info); | ||
} else { | ||
console.log('Success!', info) | ||
console.log('Success!', info); | ||
} | ||
@@ -64,6 +64,6 @@ } | ||
transport.verify(function(err, success){ | ||
if (err){ | ||
console.log('Error!', err) | ||
if (err) { | ||
console.log('Error!', err); | ||
} else { | ||
console.log('Success!', success) | ||
console.log('Success!', success); | ||
} | ||
@@ -79,42 +79,39 @@ }) | ||
const should = require('should') | ||
const mockery = require('mockery') | ||
const nodemailerMock = require('nodemailer-mock') | ||
const should = require('should'); | ||
const mockery = require('mockery'); | ||
const nodemailerMock = require('nodemailer-mock'); | ||
describe('Tests that send email', function(){ | ||
describe('Tests that send email', function() { | ||
// This could be an app, Express, etc. It should be instantiated *after* nodemailer is mocked. | ||
let app = null | ||
/* This could be an app, Express, etc. It should be | ||
instantiated *after* nodemailer is mocked. */ | ||
let app = null; | ||
before(function(){ | ||
before(function() { | ||
// Enable mockery to mock objects | ||
mockery.enable({ | ||
warnOnUnregistered: false | ||
}) | ||
warnOnUnregistered: false, | ||
}); | ||
// Once mocked, any code that calls require('nodemailer') will get our nodemailerMock | ||
/* Once mocked, any code that calls require('nodemailer') | ||
will get our nodemailerMock */ | ||
mockery.registerMock('nodemailer', nodemailerMock) | ||
// Make sure anything that uses nodemailer is loaded here, after it is mocked... | ||
}) | ||
// IMPORTANT! | ||
/* Make sure anything that uses nodemailer is loaded here, | ||
after it is mocked... */ | ||
}); | ||
afterEach(function(){ | ||
afterEach(function() { | ||
// Reset the mock back to the defaults after each test | ||
nodemailerMock.mock.reset() | ||
}) | ||
nodemailerMock.mock.reset(); | ||
}); | ||
after(function(){ | ||
after(function() { | ||
// Remove our mocked nodemailer and disable mockery | ||
mockery.deregisterAll() | ||
mockery.disable() | ||
}) | ||
mockery.deregisterAll(); | ||
mockery.disable(); | ||
}); | ||
it('should send an email using nodemailer-mock', function(done){ | ||
it('should send an email using nodemailer-mock', function(done) { | ||
// call a service that uses nodemailer | ||
@@ -124,23 +121,21 @@ var response = ... // <-- your code here | ||
// a fake test for something on our response | ||
response.value.should.be.exactly('value') | ||
response.value.should.be.exactly('value'); | ||
// get the array of emails we sent | ||
const sentMail = nodemailerMock.mock.sentMail() | ||
const sentMail = nodemailerMock.mock.sentMail(); | ||
// we should have sent one email | ||
sentMail.length.should.be.exactly(1) | ||
sentMail.length.should.be.exactly(1); | ||
// check the email for something | ||
sentMail[0].property.should.be.exactly('foobar') | ||
sentMail[0].property.should.be.exactly('foobar'); | ||
done() | ||
}) | ||
done(); | ||
}); | ||
it('should fail to send an email using nodemailer-mock', function(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) | ||
const err = 'My custom error'; | ||
nodemailerMock.mock.shouldFailOnce(); | ||
nodemailerMock.mock.failResponse(err); | ||
@@ -151,12 +146,10 @@ // call a service that uses nodemailer | ||
// a fake test for something on our response | ||
response.error.should.be.exactly(err) | ||
response.error.should.be.exactly(err); | ||
done() | ||
}) | ||
done(); | ||
}); | ||
it('should verify using the real nodemailer transport', function(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) | ||
nodemailerMock.mock.mockedVerify(false); | ||
@@ -168,8 +161,6 @@ // call a service that uses nodemailer | ||
transport.sendMail() is still mocked */ | ||
done() | ||
}) | ||
}) | ||
done(); | ||
}); | ||
}); | ||
``` |
Sorry, the diff of this file is not supported yet
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
77459
161