Needlessly Postulating Minds

    TypeScript icon, indicating that this package has built-in type declarations

    3.1.8 • Public • Published



    Build Coverage Downloads Size Platform

    Stars Twitter

    REST API Testing Tool for all levels in a Test Pyramid

    PactumJS Demo

    PactumJS is a REST API Testing Tool used to automate e2e, integration, contract & component (or service level) tests.

    • Swift
    • 🎈 Lightweight
    • 🚀 Simple & Powerful
    • 🛠️ Compelling Mock Server
    • 💎 Elegant Data Management
    • 🔧 Extendable & Customizable
    • 📚 Clear & Comprehensive Testing Style
    • 🔗 Component, Contract & E2E testing of APIs



    This readme offers an basic introduction to the library. Head over to the full documentation at

    Need Help

    We use Github Discussions to receive feedback, discuss ideas & answer questions.


    # install pactum as a dev dependency
    npm install --save-dev pactum
    # install a test runner to run pactum tests
    # mocha / jest / cucumber
    npm install --save-dev mocha



    pactum can be used for all levels of testing in a test pyramid. It can also act as an standalone mock server to generate contracts for contract testing.

    API Testing

    Tests in pactum are clear and comprehensive. It uses numerous descriptive methods to build your requests and expectations.

    Simple Test Cases

    Using Mocha

    Running simple api test expectations.

    const pactum = require('pactum');
    it('should be a teapot', async () => {
      await pactum.spec()
    it('should save a new user', async () => {
      await pactum.spec()
        .withHeaders('Authorization', 'Basic xxxx')
          name: 'bolt',
          email: ''
    # mocha is a test framework to execute test cases
    mocha /path/to/test

    Using Cucumber

    See pactum-cucumber-boilerplate for more details on pactum & cucumber integration.

    Scenario: Check Tea Pot
      Given I make a GET request to ""
      When I receive a response
      Then response should have a status 418
    // steps.js
    const pactum = require('pactum');
    const { Given, When, Then, Before } = require('@cucumber/cucumber');
    let spec = pactum.spec();
    Before(() => { spec = pactum.spec(); });
    Given('I make a GET request to {string}', function (url) {
    When('I receive a response', async function () {
      await spec.toss();
    Then('response should have a status {int}', async function (code) {

    Mock Server

    pactum can act as a standalone mock server that allows us to mock any server via HTTP or HTTPS, such as a REST endpoint. Simply it is a simulator for HTTP-based APIs.

    Running pactum as a standalone mock server.

    const { mock } = require('pactum');
      request: {
        method: 'GET',
        path: '/api/projects'
      response: {
        status: 200,
        body: [
            id: 'project-id',
            name: 'project-name'



    Inspired from frisby and pact.


    Like this project! Star it on Github and follow on Twitter. Your support means a lot to us.


    If you've ever wanted to contribute to open source, and a great cause, now is your chance! See the contributing docs for more information.

    Thanks to all the people who contribute.


    npm i pactum

    DownloadsWeekly Downloads






    Unpacked Size

    159 kB

    Total Files


    Last publish


    • asaianudeep