https://github.com/jaredhanson/chai-connect-middleware
Helpers for testing Connect middleware with the Chai assertion library.
https://github.com/jaredhanson/chai-connect-middleware
Last synced: about 1 year ago
JSON representation
Helpers for testing Connect middleware with the Chai assertion library.
- Host: GitHub
- URL: https://github.com/jaredhanson/chai-connect-middleware
- Owner: jaredhanson
- License: mit
- Created: 2013-08-27T15:51:35.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2018-01-04T16:32:00.000Z (over 8 years ago)
- Last Synced: 2025-05-13T01:45:32.621Z (about 1 year ago)
- Language: JavaScript
- Size: 25.4 KB
- Stars: 8
- Watchers: 2
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# chai-connect-middleware
[](https://www.npmjs.com/package/chai-connect-middleware)
[](https://travis-ci.org/jaredhanson/chai-connect-middleware)
[](https://codeclimate.com/github/jaredhanson/chai-connect-middleware)
[](https://coveralls.io/r/jaredhanson/chai-connect-middleware)
[](https://david-dm.org/jaredhanson/chai-connect-middleware)
Helpers for testing [Connect](http://www.senchalabs.org/connect/) middleware
with the [Chai](http://chaijs.com/) assertion library.
## Install
$ npm install chai-connect-middleware
## Usage
#### Use Plugin
Use this plugin as you would all other Chai plugins:
```javascript
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 `end`s the response. If the middleware
finishes in an unexpected way, the test helper will automatically throw an
exception.
The following demonstrates a [Mocha](http://mochajs.org/) test
case.
```javascript
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](http://opensource.org/licenses/MIT)
Copyright (c) 2013-2017 Jared Hanson <[http://jaredhanson.net/](http://jaredhanson.net/)>