Skip to content
On this page

Empower Your Test Results with AI-Powered Insights ->

Quick Start

PactumJS is a Node.js project & available as an npm package under the name pactum.

TIP

PactumJS is not a test runner. It needs to be used alongside with a test runner like mocha, jest, jasmine, cucumber or build your own if your heart desires, pactum should work out of the box.

System Requirements

Node.js 10 and above - Download NodeJS

To write better maintainable tests -

Installation

  • Install pactum via npm.
shell
# install pactum
npm install -D pactum

# install a test runner
npm install -D mocha
  • Install pactum via npx.
shell
npx pactum-init

Writing Tests

Sample pactum test with mocha.

js
// test.js
const { spec } = require('pactum');

it('should get a response with status code 200', async () => {
  await spec()
    .get('http://httpbin.org/status/200')
    .expectStatus(200);
});

Running Tests

Update the scripts in package.json

json
{
  "scripts": {
    "test": "mocha test.js"
  }
}

Now run the following command in terminal.

shell
npm run test

Cucumber

Cucumber is a popular option in many organizations to write tests.

Released under the MIT License.