Skip to content
On this page

Empower Your Test Results with AI-Powered Insights ->

withForm

It provides a easy way to construct a set of key/value pairs representing form fields and their values.

content-type header will be auto updated to application/x-www-form-urlencoded

Syntax

js
withForm(key, value)
withForm(form-object)
  • key (string) - key of the form field.
  • value (string) - value of the form field.
  • form-object (object) - key value pairs of form fields.

Usage

โœ… Correct Usage

js
await spec()
  .post('/forms/posts')
  .withForm({
    "user": 'jon',
    "password": 'abc'
  })
  .expectStatus(201);

Examples

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

await spec()
  .post('https://httpbin.org/forms/posts')
  .withForm({
    "user": 'jon',
    "password": 'abc'
  })
  .expectStatus(201);

Notes

See Also

Released under the MIT License.