PactumJS is a lightweight and powerful open-source REST API testing tool designed to automate various levels of API testing, including end-to-end (e2e), integration, contract, and component (service level) tests. It emphasizes a clear and comprehensive testing style, utilizing numerous descriptive methods for building requests and defining expectations. The current stable version is 3.9.1, with minor releases occurring frequently, demonstrating active development and maintenance. Key differentiators include its compelling built-in mock server, elegant data management capabilities for dynamic values, robust built-in JSON schema validation, and an extendable architecture. PactumJS supports various JavaScript test runners like Mocha, Jest, and Cucumber, making it adaptable to different testing frameworks and helping simplify complex API testing scenarios across the entire test pyramid.
npm install pactumVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic GET and POST requests, status code assertions, and JSON body matching using PactumJS with an ESM setup and environment variable for authentication.
Install a test runner (e.g., `npm install --save-dev mocha`) and configure your `package.json` scripts to run tests (e.g., `"test": "mocha tests/**/*.js"`).
Ensure all PactumJS operations that return a Promise are prefixed with `await` and that their containing test function is marked `async` (e.g., `it('...', async () => { await spec()... })`).Always check the exact casing of the header in the actual API response (e.g., via a proxy or network inspector) or try using a common lowercase variant like `'content-type'`.
Refer to the PactumJS documentation for setting up the `pactumjs-flow-server` (e.g., via Docker) and configuring your project to publish/consume flows and interactions.
Utilize test runner hooks (`beforeEach`, `afterEach`) to set up and tear down global configurations, or use localized settings within `spec()` chains where possible to ensure test isolation.
Ensure all PactumJS methods (e.g., `spec()`, `spec().toss()`) are prefixed with `await` and the test function is marked `async`.
Check the exact casing of the header in the actual API response (e.g., via a proxy or network inspector) or try using a common lowercase variant like `'content-type'`.
Use named import: `import { spec } from 'pactum'` (ESM) or object destructuring: `const { spec } = require('pactum')` (CommonJS).No dependency data recorded yet.