Skip to content

Helpers for testing Connect middleware with the Chai assertion library.

License

Notifications You must be signed in to change notification settings

jaredhanson/chai-connect-middleware

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

chai-connect-middleware

Version Build Quality Coverage 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'));

Implement 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');
  });
});

License

The MIT License

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

Sponsor

About

Helpers for testing Connect middleware with the Chai assertion library.

Resources

License

Stars

Watchers

Forks

Packages

No packages published