New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

hof-util-reqres

Package Overview
Dependencies
Maintainers
4
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hof-util-reqres

Test helper to create dummy request/response objects for testing middleware methods

latest
Source
npmnpm
Version
1.1.0
Version published
Maintainers
4
Created
Source

hof-util-reqres

Test helper to create dummy request/response objects for testing middleware methods

Usage

In your tests you can use the provided req and res methods to create objects with additional properties that we would expect to exist on a request that had passed through a hof request pipeline.

const request = require('hof-util-reqres').req;
const req = request();

it('provides a sessionModel property on the request', () => {
  expect(req.sessionModel).to.be.an.instanceOf(require('hof-model'));
});

it('provides a translate property on the request', () => {
  expect(req.translate).to.be.a('function');
});

it('provides a form property on the request with values', () => {
  expect(req.form).to.eql({ values: {} });
});

Additionally, the request and response objects will have all properties and methods exposed by express. Response methods will be instances of sinon stubs, and so can have assertions made against their calls.

See reqres module for further details of default express behaviour.

Session Data

The session model can be pre-populated by passing a session option.

const request = require('hof-util-reqres').req;
const req = request({
  session: { name: 'Alice' }
});

it('populates session model with `session` parameter', () => {
  expect(req.sessionModel.get('name')).to.equal('Alice');
});

FAQs

Package last updated on 20 Oct 2017

Did you know?

Socket

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.

Install

Related posts