# sinon-express-mock

> Simple request and response mock objects to pass into Express routes when testing using Sinon.

Latest version **2.2.1** (published 2019-08-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install sinon-express-mock
pnpm add sinon-express-mock
yarn add sinon-express-mock
bun add sinon-express-mock
```

## Health

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

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.2.1 |
| Published | 2019-08-21 |
| First published | 2015-11-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/sinon-express-mock) |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 7.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 46 |
| Author | Dana Woodman |
| Maintainers | danawoodman |
| Keywords | express, mock, test, request, response, req, res, spec, mocha, sinon, spy |

## Links

- npm: https://www.npmjs.com/package/sinon-express-mock
- Repository: https://github.com/danawoodman/sinon-express-mock
- Homepage: https://github.com/danawoodman/sinon-express-mock#readme
- Issues: https://github.com/danawoodman/sinon-express-mock/issues
- npm.io page: https://npm.io/package/sinon-express-mock

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads
- [aws-elasticsearch-connector](https://npm.io/package/aws-elasticsearch-connector.md) — 37.4K weekly downloads

## Recent versions

- 2.2.1 (latest) — 2019-08-21
- 2.2.0 — 2019-03-30
- 2.1.0 — 2018-11-01
- 2.0.5 — 2018-07-24
- 2.0.4 — 2018-05-28
- 2.0.2 — 2018-05-22
- 2.0.1 — 2018-05-22
- 2.0.0 — 2017-12-29
- 1.3.1 — 2017-06-02
- 1.3.0 — 2017-03-28
- 1.2.4 — 2016-02-05
- 1.2.3 — 2016-02-05
- 1.2.2 — 2016-02-04
- 1.2.1 — 2016-02-04
- 1.2.0 — 2016-02-04
- … 2 more at https://npm.io/package/sinon-express-mock/versions

## README

# sinon-express-mock

Simple request and response mock objects to pass into Express routes when testing using Sinon.

The mock objects attach Sinon spys to request methods. See `src/index.js` for a full list of stubbed out methods.

## Install

```shell
npm install --save-dev sinon-express-mock sinon
```

Depends on:

* Node v4+ (or `Object.assign` support needed)
* Sinon

## Usage

Contents of `src/foo.js`:

```js
export default (req, res) => {
  res.json({ foo: req.body.foo })
}
```

Contents of `test/foo-test.js`:

```js
import route from '../src/foo'
import chai, { expect } from 'chai'
import sinonChai from 'sinon-chai'
import { mockReq, mockRes } from 'sinon-express-mock'

chai.use(sinonChai);

describe('my route', () => {
  it('should foo the bar', () => {
    const request = {
      body: {
        foo: 'bar',
      },
    }
    const req = mockReq(request)
    const res = mockRes()

    route(req, res)

    expect(res.json).to.be.calledWith({ foo: request.body.foo })
  })
})
```

## Changelog

### v2.0.3

* `res.write()` is now stubbed.

### v2.0.0

* Make sinon a `peerDependency`.

### v1.3.1

* Bundle fix from #3

### pre v1.3.1

* Changelog didn't exist! 😱

## Credits

Dana Woodman and [contributors](https://github.com/danawoodman/sinon-express-mock/graphs/contributors)

## License

MIT

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