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

@types/nock

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@types/nock

Stub TypeScript definitions entry for nock, which provides its own types definitions

  • 11.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
106K
decreased by-32.92%
Maintainers
1
Weekly downloads
 
Created

What is @types/nock?

@types/nock provides TypeScript type definitions for the nock library, which is used for HTTP mocking and expectations in Node.js applications.

What are @types/nock's main functionalities?

Mocking HTTP Requests

This feature allows you to mock HTTP GET requests to a specified URL and return a predefined response. In this example, a GET request to 'http://example.com/resource' will return a 200 status code with a JSON body.

const nock = require('nock');
const scope = nock('http://example.com')
  .get('/resource')
  .reply(200, { id: 1, name: 'Resource' });

Intercepting and Modifying Requests

This feature allows you to intercept HTTP POST requests with a specific request body and return a predefined response. In this example, a POST request to 'http://example.com/resource' with a JSON body will return a 201 status code with a JSON response.

const nock = require('nock');
const scope = nock('http://example.com')
  .post('/resource', { name: 'New Resource' })
  .reply(201, { id: 2, name: 'New Resource' });

Simulating Network Errors

This feature allows you to simulate network errors for HTTP requests. In this example, a GET request to 'http://example.com/resource' will result in a network error.

const nock = require('nock');
const scope = nock('http://example.com')
  .get('/resource')
  .replyWithError('Network error');

Delay Responses

This feature allows you to introduce a delay before sending the response. In this example, a GET request to 'http://example.com/resource' will be delayed by 2000 milliseconds before returning a 200 status code with a JSON body.

const nock = require('nock');
const scope = nock('http://example.com')
  .get('/resource')
  .delay(2000)
  .reply(200, { id: 1, name: 'Resource' });

Other packages similar to @types/nock

FAQs

Package last updated on 11 Sep 2019

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