New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

mockttp

Package Overview
Dependencies
Maintainers
1
Versions
127
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mockttp

Mock HTTP server for testing HTTP clients and stubbing webservices

  • 0.12.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
163K
increased by6.84%
Maintainers
1
Weekly downloads
 
Created

What is mockttp?

Mockttp is a versatile HTTP mocking library for Node.js, designed to help developers test HTTP-based applications by simulating HTTP servers and requests. It allows you to create mock servers, define request handlers, and verify interactions, making it easier to test how your application handles different HTTP scenarios.

What are mockttp's main functionalities?

Create a mock server

This feature allows you to create and start a local mock server on a specified port. The code sample demonstrates how to start a mock server on port 8080 and log its URL.

const { getLocal } = require('mockttp');

(async () => {
  const mockServer = getLocal();
  await mockServer.start(8080);
  console.log(`Mock server running at ${mockServer.url}`);
})();

Mock HTTP requests

This feature allows you to define how the mock server should respond to specific HTTP requests. The code sample shows how to mock a GET request to '/example' and respond with a 200 status and 'Hello, world!' message.

const { getLocal } = require('mockttp');

(async () => {
  const mockServer = getLocal();
  await mockServer.start(8080);

  await mockServer.forGet('/example').thenReply(200, 'Hello, world!');
})();

Verify request interactions

This feature allows you to verify that certain requests were made to the mock server. The code sample demonstrates how to check the number of times a mocked endpoint was accessed.

const { getLocal } = require('mockttp');

(async () => {
  const mockServer = getLocal();
  await mockServer.start(8080);

  const endpointMock = await mockServer.forGet('/example').thenReply(200, 'Hello, world!');

  // Later, verify the request was made
  const requests = await endpointMock.getSeenRequests();
  console.log(`Number of requests made: ${requests.length}`);
})();

Other packages similar to mockttp

Keywords

FAQs

Package last updated on 01 Dec 2018

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