JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 24171
  • Score
    100M100P100Q152610F
  • License MIT

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

Package Exports

  • sinon-express-mock

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (sinon-express-mock) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

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. Currently that list includes:

  • locals
  • render()
  • json()
  • redirect()
  • sendStatus()

Install

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

Depends on:

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

Usage

Contents of src/foo.js:

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

Contents of test/foo-test.js:

import route from '../src/foo'
import { mockReq, mockRes } from 'sinon-express-mock'

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.bar })
  })
})

License

MIT