Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
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
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
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.