
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
email-templates-mock
Advanced tools
Mocked email-templates@2.x
module for testing
npm install email-templates-mock --save-dev
yarn add -D email-templates-mock
There are some special methods available on the mocked module to help with testing.
emailtemplatesMock.mock.mockedRender(true|false)
email-templates
false
, use email-templates
- this is the defaulttrue
, use a mocked callback and emailemailtemplatesMock.mock.validateTemplateDir(true|false)
emailtemplatesMock.mock.reset()
emailtemplatesMock.mock.shouldFailOnce()
template.render()
emailtemplatesMock.mock.shouldFail(true|false)
template.render()
true
, return errorfalse
, return successemailtemplatesMock.mock.email(email)
template.render()
emailtemplatesMock.mock.failResponse(err)
template.render()
The mocked module behaves in a similar fashion to templates provided by email-templates
.
'use strict'
const emailtemplatesMock = require('email-templates-mock')
const templateDir = path.join(__dirname, './templates/example')
const template = new emailtemplatesMock.EmailTemplate(templateDir)
// the inputs for the templates
const inputs = {}
template.render(inputs, function(err, email){
if (err){
console.log('Error!', err, info)
} else {
console.log('Success!', email)
}
}
Here is an example of using a mocked nodemailer
class in a mocha
test using mockery
'use strict'
const should = require('should')
const mockery = require('mockery')
const emailtemplatesMock = require('email-templates-mock')
describe('Tests that render an email', function(){
/* This could be an app, Express, etc. It should be
instantiated *after* email-templates is mocked. */
let app = null
before(function(){
// Enable mockery to mock objects
mockery.enable({
warnOnUnregistered: false
})
/* Once mocked, any code that calls require('email-templates')
will get our emailtemplatesMock */
mockery.registerMock('email-templates', emailtemplatesMock)
/* Make sure anything that uses email-templates is
loaded here, after it is mocked... */
})
afterEach(function(){
// Reset the mock back to the defaults after each test
emailtemplatesMock.mock.reset()
})
after(function(){
// Remove our mocked nodemailer and disable mockery
mockery.deregisterAll()
mockery.disable()
})
const inputs {
// your inputs
}
it('should render using email-templates-mock', function(done){
template.render(inputs, function(err, email){
should(err).equal(null)
should(email).not.equal(null)
email.should.match(/this string/)
done()
})
})
it('should fail to render using email-templates-mock', function(done){
emailtemplatesMock.mock.shouldFailOnce()
template.render(inputs, function(err, email){
should(err).not.equal(null)
done()
})
})
})
FAQs
Mock email-templates module for unit testing
The npm package email-templates-mock receives a total of 1 weekly downloads. As such, email-templates-mock popularity was classified as not popular.
We found that email-templates-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
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.