Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/danawoodman/sinon-express-mock
Simple request and response mock objects to pass into Express routes when testing using Sinon.
https://github.com/danawoodman/sinon-express-mock
epub helper mock route router sinon test testing util utility
Last synced: 5 days ago
JSON representation
Simple request and response mock objects to pass into Express routes when testing using Sinon.
- Host: GitHub
- URL: https://github.com/danawoodman/sinon-express-mock
- Owner: danawoodman
- License: mit
- Created: 2015-11-22T07:43:43.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2023-06-26T18:27:21.000Z (over 1 year ago)
- Last Synced: 2024-10-04T11:27:52.691Z (about 1 month ago)
- Topics: epub, helper, mock, route, router, sinon, test, testing, util, utility
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/sinon-express-mock
- Size: 59.6 KB
- Stars: 47
- Watchers: 5
- Forks: 16
- Open Issues: 4
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
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