![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
@types/nock
Advanced tools
TypeScript definitions for nock
@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.
npm install --save @types/nock
This package contains type definitions for nock ( https://github.com/nock/nock ).
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/nock
Additional Details
These definitions were written by bonnici https://github.com/bonnici, Horiuchi_H https://github.com/horiuchi, afharo https://github.com/afharo, Matt R. Wilson https://github.com/mastermatt, Garanzha Dmitriy https://github.com/damour, GP https://github.com/paambaati.
FAQs
Stub TypeScript definitions entry for nock, which provides its own types definitions
The npm package @types/nock receives a total of 62,493 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
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.