Socket
Socket
Sign inDemoInstall

sinon-express-mock

Package Overview
Dependencies
13
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    sinon-express-mock

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


Version published
Weekly downloads
23K
decreased by-4.16%
Maintainers
1
Install size
8.32 kB
Created
Weekly downloads
 

Readme

Source

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

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

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

Contents of test/foo-test.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

License

MIT

Keywords

FAQs

Last updated on 21 Aug 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc