Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hof-component-date

Package Overview
Dependencies
Maintainers
5
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hof-component-date - npm Package Compare versions

Comparing version 1.2.0 to 1.3.0

.idea/.name

7

lib/date.js

@@ -42,2 +42,6 @@ 'use strict';

const getLegendClassName = field => {
return field && field.legend && field.legend.className || '';
};
module.exports = (key, options) => {

@@ -112,4 +116,5 @@ if (!key) {

const hint = conditionalTranslate(`fields.${key}.hint`, req.translate);
const legendClassName = getLegendClassName(options);
const error = req.form.errors && req.form.errors[key];
res.render(template, { key, legend, hint, error }, (err, html) => {
res.render(template, { key, legend, legendClassName, hint, error }, (err, html) => {
if (err) {

@@ -116,0 +121,0 @@ next(err);

2

package.json
{
"name": "hof-component-date",
"version": "1.2.0",
"version": "1.3.0",
"description": "A hof middleware for rendering and processing 3 part date fields",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -145,5 +145,5 @@ 'use strict';

it('calls res.render with template, key, legend and hint. Where the latter two are null', () => {
it('calls res.render with template & key.', () => {
date.hooks['pre-render'](req, res, next);
expect(res.render).to.have.been.calledWith(path.resolve(__dirname, '../templates/date.html'), { error: undefined, key: 'date-field', legend: null, hint: null });
expect(res.render).to.have.been.calledWith(path.resolve(__dirname, '../templates/date.html'), sinon.match({key: 'date-field'}));
});

@@ -157,6 +157,6 @@

date.hooks['pre-render'](req, res, next);
expect(res.render).to.have.been.calledWith(path.resolve(__dirname, '../templates/date.html'), { error, key: 'date-field', legend: null, hint: null });
expect(res.render).to.have.been.calledWith(sinon.match.string, sinon.match({error}));
});
it('calls res.render with template, key, legend and hint with values NOT null', () => {
it('calls res.render with a legend and hint', () => {
req.translate = sinon.stub();

@@ -166,5 +166,19 @@ req.translate.withArgs('fields.date-field.legend').returns('you legend');

date.hooks['pre-render'](req, res, next);
expect(res.render).to.have.been.calledWith(path.resolve(__dirname, '../templates/date.html'), { error: undefined, key: 'date-field', legend: 'you legend', hint: 'some hint' });
const args = res.render.lastCall.args;
expect(args[1]).to.have.property('legend').and.to.equal('you legend');
expect(args[1]).to.have.property('hint').and.to.equal('some hint');
});
it('checks the legendClassName and the value', () => {
date = dateComponent('date-field', {
legend: {
className: 'testClass'
}
});
date.hooks['pre-render'](req, res, next);
const args = res.render.lastCall.args;
expect(args[1]).to.have.property('legendClassName');
expect(args[1].legendClassName).to.equal('testClass');
});
it('calls next with an error if res.render calls callback with err', () => {

@@ -171,0 +185,0 @@ res.render.yields('err');

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc