# chai-connect-middleware

> Helpers for testing Connect middleware with the Chai assertion library.

Latest version **0.3.1** (published 2014-01-04) · 0 weekly downloads

## Install

```sh
npm install chai-connect-middleware
pnpm add chai-connect-middleware
yarn add chai-connect-middleware
bun add chai-connect-middleware
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.1 |
| Published | 2014-01-04 |
| First published | 2013-08-27 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 0.4.0 |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | Jared Hanson |
| Maintainers | jaredhanson |
| Keywords | chai, connect, express, middleware |

## Links

- npm: https://www.npmjs.com/package/chai-connect-middleware
- Repository: https://github.com/jaredhanson/chai-connect-middleware
- Issues: http://github.com/jaredhanson/chai-connect-middleware/issues
- npm.io page: https://npm.io/package/chai-connect-middleware

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 0.3.1 (latest) — 2014-01-04
- 0.3.0 — 2013-11-27
- 0.2.0 — 2013-11-15
- 0.1.1 — 2013-08-28
- 0.1.0 — 2013-08-27

## README

# chai-connect-middleware

[![Build](https://travis-ci.org/jaredhanson/chai-connect-middleware.png)](https://travis-ci.org/jaredhanson/chai-connect-middleware)
[![Coverage](https://coveralls.io/repos/jaredhanson/chai-connect-middleware/badge.png)](https://coveralls.io/r/jaredhanson/chai-connect-middleware)
[![Quality](https://codeclimate.com/github/jaredhanson/chai-connect-middleware.png)](https://codeclimate.com/github/jaredhanson/chai-connect-middleware)
[![Dependencies](https://david-dm.org/jaredhanson/chai-connect-middleware.png)](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'));
```

#### 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 `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://visionmedia.github.io/mocha/) 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');
  });
});
```

## Tests

    $ npm install
    $ npm test

## Credits

  - [Jared Hanson](http://github.com/jaredhanson)

## License

[The MIT License](http://opensource.org/licenses/MIT)

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

---
_Source: https://npm.io/package/chai-connect-middleware · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
