0.3.1 • Published 10 years ago

chai-connect-middleware v0.3.1

Weekly downloads
119
License
-
Repository
github
Last release
10 years ago

chai-connect-middleware

Build 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')
  , connect = require('chai-connect-middleware');

chai.use(connect);

Write Test Cases

Once used, the chai.connect 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 = res;
    
  before(function(done) {
    chai.connect(middleware)
      .req(function(req) {
        req.query = { hello: 'Bob' };
      })
      .end(function(r) {
        res = r;
        done();
      })
      .dispatch(new Error('something went wrong'));
  });

  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/](http://jaredhanson.net/)

0.3.1

10 years ago

0.3.0

10 years ago

0.2.0

10 years ago

0.1.1

11 years ago

0.1.0

11 years ago