Socket
Socket
Sign inDemoInstall

chai-connect-middleware

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chai-connect-middleware

Helpers for testing Connect middleware with the Chai assertion library.


Version published
Weekly downloads
100
increased by138.1%
Maintainers
1
Weekly downloads
 
Created
Source

chai-connect-middleware

Build Coverage Quality Dependencies

Helpers for testing Connect middleware with the Chai assertion library.

Install

$ npm install chai-connect-middleware

Usage

Use Plugin

Use this plugin as you would all other Chai plugins:

var chai = require('chai');

chai.use(require('chai-connect-middleware'));
Write Test Cases

Once used, the chai.connect.use helper function will be available to set up test cases for Connect middleware.

The helper function can be called from a hook to setup the test case. The helper returns a wrapper on which callbacks are registered to be executed when the middleware invokes next or ends the response. If the middleware finishes in an unexpected way, the test helper will automatically throw an exception.

The following demonstrates a Mocha test case.

describe('middleware test', function() {
  var res;
    
  before(function(done) {
    chai.connect.use(middleware)
      .req(function(req) {
        req.query = { hello: 'Bob' };
      })
      .end(function(r) {
        res = r;
        done();
      })
      .dispatch();
  });

  it('should send correct body', function() {
    expect(res.body).to.equal('Hello, Bob');
  });
});

Tests

$ npm install
$ npm test

Credits

License

The MIT License

Copyright (c) 2013 Jared Hanson <http://jaredhanson.net/>

Keywords

FAQs

Package last updated on 04 Jan 2014

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

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