Skip to content
On this page

Empower Your Test Results with AI-Powered Insights ->

use

Runs the spec handler to set request and response details.

Syntax

js
use(handler-name)

Usage

โœ… Correct Usage

js
await spec()
  .use('get user')
  .expectJson('data.first_name', 'George');

Arguments

> handler-name (string)

Name of the spec handler to use.

Examples

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

handler.addSpecHandler('get user', () => {
  const { spec, data } = ctx;
  spec.get('https://reqres.in/api/users/{id}');
  spec.withPathParams('id', data || 1)
  spec.expectStatus(200);
});

await spec().use('get user').expectJson('data.first_name', 'George');
await spec().use('get user', 2).expectJson('data.first_name', 'Janet');

See Also

Released under the MIT License.