Skip to content
On this page

Empower Your Test Results with AI-Powered Insights ->

setDefaultExpectHandlers

set default expect handlers for all the response assertions.

Syntax

js
setDefaultExpectHandlers(handler, data)
  • handler (string) - name of the expect handler
  • data (any) - custom data to be passed to handler

Usage

โœ… Correct Usage

js
response.setDefaultExpectHandlers('user', 'gender')

Examples

Normal

js
const { handler, spec, response } = require('pactum');
const { expect } = require("chai")

handler.addExpectHandler('user', (ctx) => {
  // ctx.data will have 'gender'
  expect(ctx.res.json.results[0]).to.have.property(ctx.data);
});

response.setDefaultExpectHandlers('user', 'gender')

await spec()
  .get('https://randomuser.me/api')
  .expectStatus(200);

See Also

Released under the MIT License.