Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
@types/nock
Advanced tools
Stub TypeScript definitions entry for nock, which provides its own types definitions
@types/nock provides TypeScript type definitions for the nock library, which is used for HTTP mocking and expectations in Node.js applications.
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' });
axios-mock-adapter is a library that allows you to easily mock requests made with axios. It provides a simple API for intercepting requests and returning custom responses. Compared to nock, axios-mock-adapter is specifically designed for axios and may be easier to use if you are already using axios in your project.
fetch-mock is a library for mocking fetch requests. It provides a flexible API for intercepting fetch requests and returning custom responses. Compared to nock, fetch-mock is specifically designed for the Fetch API and is a good choice if you are using fetch for HTTP requests in your project.
supertest is a library for testing HTTP servers. It provides a high-level API for making HTTP requests and asserting responses. While supertest is not specifically designed for mocking, it can be used to test HTTP endpoints in a similar way to nock. It is a good choice if you are looking for a more comprehensive testing solution that includes HTTP request testing.
This is a stub types definition for nock (https://github.com/nock/nock).
nock provides its own type definitions, so you don't need @types/nock installed!
FAQs
Stub TypeScript definitions entry for nock, which provides its own types definitions
The npm package @types/nock receives a total of 86,008 weekly downloads. As such, @types/nock popularity was classified as popular.
We found that @types/nock demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.