{"id":17266,"library":"http-testify","title":"HTTPtestify","description":"HTTPtestify is a Node.js library designed for comprehensive integration testing of HTTP APIs. It provides a promise-based API, drawing inspiration from Axios, to facilitate making HTTP requests, asserting response properties, and conducting end-to-end tests. The current stable version is 1.0.3, with releases driven by feature additions and minor bug fixes rather than a strict schedule. Key differentiators include its extensive support for various HTTP methods (GET, POST, PUT, DELETE), advanced request customization (headers, body, query parameters), and sophisticated parallel request handling capabilities like `all`, `race`, and `allSettled`. The library also offers features such as request cancellation, proxy support, robust cookie and session management, and automatic parsing of JSON and optional XML responses, making it a versatile tool for complex API testing scenarios.","status":"active","version":"1.0.3","language":"javascript","source_language":"en","source_url":"https://github.com/alok-shete/http-testify","tags":["javascript","HTTP-testify","Mock Server","API Testing","HTTP Requests","HTTP Methods","Mocking","Mocking Framework","Node.js","typescript"],"install":[{"cmd":"npm install http-testify","lang":"bash","label":"npm"},{"cmd":"yarn add http-testify","lang":"bash","label":"yarn"},{"cmd":"pnpm add http-testify","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"While the library's `README` uses `require` for CommonJS, modern Node.js applications and TypeScript projects should prefer the ESM `import` syntax. The package is designed with TypeScript in mind, ensuring proper type inference with `import`.","wrong":"const HTTPtestify = require('http-testify');","symbol":"HTTPtestify","correct":"import HTTPtestify from 'http-testify';"},{"note":"`request` is a method on the default-imported `HTTPtestify` object, used to initialize a test server instance. It is not a named export that can be destructured directly from the package.","wrong":"import { request } from 'http-testify';","symbol":"request","correct":"const server = HTTPtestify.request(app);"},{"note":"HTTP methods like `get`, `post`, `put`, etc., are invoked on the `server` instance returned by `HTTPtestify.request(app)`, not directly on the main `HTTPtestify` object.","wrong":"HTTPtestify.get('/api/data').then(...);","symbol":"get","correct":"server.get('/api/data').then(...);"}],"quickstart":{"code":"import HTTPtestify from 'http-testify';\nimport express from 'express'; // Common framework for HTTP APIs\n\n// 1. Create a minimal Express app instance for testing\nconst app = express();\napp.use(express.json()); // Enable JSON body parsing for POST requests\n\n// Define a simple GET endpoint\napp.get('/api/status', (req, res) => {\n  res.status(200).json({ status: 'ok', version: '1.0' });\n});\n\n// Define a simple POST endpoint\napp.post('/api/submit', (req, res) => {\n  const data = req.body;\n  res.status(201).json({ message: 'Data received', received: data });\n});\n\n// 2. Initialize HTTPtestify with the app instance\nconst server = HTTPtestify.request(app);\n\n// 3. Define an async test function\nasync function runExampleTests() {\n  try {\n    // Perform a GET request\n    const getResponse = await server.get('/api/status');\n    console.log('GET /api/status Status:', getResponse.status); // Expected: 200\n    console.log('GET /api/status Data:', getResponse.data);    // Expected: { status: 'ok', version: '1.0' }\n\n    // Perform a POST request with a JSON body\n    const postResponse = await server.post('/api/submit', { item: 'widget', quantity: 5 });\n    console.log('POST /api/submit Status:', postResponse.status); // Expected: 201\n    console.log('POST /api/submit Data:', postResponse.data);    // Expected: { message: 'Data received', received: { item: 'widget', quantity: 5 } }\n\n    // Demonstrate parallel GET requests\n    const [res1, res2] = await server.all((instance) => [\n      instance.get('/api/status'),\n      instance.get('/api/status')\n    ]);\n    console.log('Parallel Requests Results:', res1.status, res2.status);\n\n    console.log('\\nAll example tests completed successfully!');\n  } catch (error) {\n    console.error('An error occurred during tests:', error);\n  }\n}\n\nrunExampleTests();","lang":"typescript","description":"Demonstrates how to set up `http-testify` with a simple Express server, make GET and POST requests, and execute parallel requests, logging their responses."},"warnings":[{"fix":"Use `import HTTPtestify from 'http-testify';` and ensure `type: 'module'` in `package.json` or configure TypeScript to emit ESM.","message":"When migrating from older CommonJS (`require`) patterns to modern ESM (`import`) in Node.js, ensure your project's `package.json` and TypeScript configuration are set up for ESM, as `http-testify` ships with types and is designed for modern usage.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Always use `await` with `http-testify` methods in `async` functions, or chain `.then()` for successful responses and `.catch()` for error handling.","message":"Asynchronous operations with `http-testify` require proper handling of Promises. Forgetting `await` or neglecting `.then().catch()` chains can lead to tests completing prematurely or unhandled promise rejections, making debugging difficult.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Design tests to be stateless where possible. For stateful scenarios, use test runner hooks (e.g., `beforeEach`, `afterEach` in Jest/Mocha) to reset application state or mock external dependencies.","message":"While `http-testify` manages the lifecycle of its internal mock server, it's crucial to ensure proper test isolation and cleanup within your test suite. Shared state or external resources not properly reset between tests can lead to flaky results.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Import the default `HTTPtestify` object and then call `HTTPtestify.request(app)`.","cause":"Attempting to destructure `request` as a named import (e.g., `import { request } from 'http-testify'`) when it's a method on the default export.","error":"TypeError: HTTPtestify.request is not a function"},{"fix":"Verify the endpoint path, HTTP method, and server-side route definitions. Check server logs for internal errors during the request.","cause":"The tested API endpoint returned an unexpected HTTP status code, often due to an incorrect route, missing handler, or server-side error.","error":"AssertionError: Expected status 200, got 404"},{"fix":"Wrap asynchronous test code in `try...catch` blocks, or ensure all Promises are handled with `.catch()` to log or assert on errors explicitly.","cause":"An `http-testify` operation (or subsequent assertion) rejected a Promise, and the rejection was not caught by an `await` within a `try/catch` block or a `.catch()` handler.","error":"UnhandledPromiseRejectionWarning: This error originated either by throwing an error inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch()."}],"ecosystem":"npm","meta_description":null}