Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

superagent-nock-patch

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

superagent-nock-patch

Mock superagent http requests

  • 0.3.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

superagent-nock

Very simple mock of superagent http requests for testing purpose (from Node.js or the browser). Inspired by superagent-mocker, superagent-mock and nock.

Used for testing React components with Redux and Observable.

Usage

Setup

import request from 'superagent';
import nocker from 'superagent-nock';
const nock = nocker(request);

Use

Define the base url

nock('http://localhost')

The url to mock

nock.get('/events/10')

The result to return

nock.reply(httpStatus, responseBody)

or specify a function

nock.reply(function() {
   return {
      status: 200,
      result: responseBody
   };
})

Then, when you do a get request on the url, the callback return the specified result

nock('http://localhost')
   .get('/events/10')
   .reply(200, {
    	id: 10,
      title: 'My event'
   });

request
   .get('http://localhost/events/10')
   .end((err, res) => {
      console.log(res.body); // { id: 10, title: 'My event'}
   };

Chaining

You can chain your urls to mock:

nock('http://localhost')
   .get('/events/10')
   .reply(200, {
	    id: 10,
	    title: 'My event'
   })
	 .get('/members/1')
   .reply(404);

Install

You should probably install it in devDependencies (-D)

$ npm i -D superagent-nock

Next TODO

nock.delay nock.query

Keywords

FAQs

Package last updated on 14 Nov 2017

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc