You might be interested in the small package I am compiling, which makes it easy to create mock requests / responses using Sinon.
Essentially, it simply creates an object that mimics the standard req / res from an expression and replaces the method with spys, which you can test.
From README:
Your test:
import route from '../src/foo' import { mockReq, mockRes } from 'sinon-express-mock' describe('my route', () => { it('should foo the bar', () => { const body = { body: { foo: 'bar', }, } const req = mockReq(body) const res = mockRes() route(req, res) expect(res.json).to.be.calledWith({ foo: body.foo.bar }) }) })
Content src/foo.js :
export default (req, res) => { res.json({ foo: req.body.bar }) }
https://github.com/danawoodman/sinon-express-mock
source share