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

expect-express

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

expect-express

common express testing assertions

latest
Source
npmnpm
Version
1.2.0
Version published
Maintainers
1
Created
Source

expect-express

Travis Codecov npm downloads

check common express unit test scenarios with expect

  • setup your imports and configure expect-express
const router = require('express').Router();
const expect = require('expect');
const expectExpress = require('expect-express');
expect.extend(expectExpress);
  • define your system under test
function responseMiddlware(req, res, next) {
    res.status(200).json({success: true});
}
function namedMiddleware(req, res, next) {
    next();
}

router.get('/:id', namedMiddleware, (req, res, next) => { next(); }, () => {});
  • test if a route is defined by specifying an HTTP verb and a path
expect(router).toHaveRoute('GET', '/:id');
  • test if a given route has params defined getRoute helper methods facilitates route selection
expect(expectExpress.helper.getRoute(router, 'GET', '/:id')).toHaveRouteParameter('id');
  • test if specific middleware (function, name or anonymous) is defined for given route
expect(expectExpress.helper.getRoute(router, 'GET', '/:id')).toHaveMiddleware(namedMiddleware);
expect(expectExpress.helper.getRoute(router, 'GET', '/:id')).toHaveMiddleware('namedMiddleware');
expect(expectExpress.helper.getRoute(router, 'GET', '/:id')).toHaveMiddleware();
  • test if middleware function returns expected response
const reqDefinition = {
    verb: 'POST',
    url: '/',
    payloadType: 'body',
    payload: { test: 'valid' }
};
expect(responseMiddleware).toRespondWith(reqDefinition, 200, {success: true});
  • test if next was called in middleware
expect(namedMiddleware).toHaveCalledNext(reqDefinition);

Keywords

expect

FAQs

Package last updated on 05 Mar 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