Skip to content
On this page

Empower Your Test Results with AI-Powered Insights ->

expectJsonMatch

Assert a JSON using a set of matchers.

See Matching for more usage details.

Syntax

js
expectJsonMatch(json)
expectJson(template-name)
expectJson(file-path)
expectJson(file-name)
expectJsonMatch(path, json)

Usage

โœ… Correct Usage

js
await spec()
  .get('api/users/1')
  .expectJsonMatch({
    id: like(1)
  });

Arguments

> json (object)

Response json body.

> path (string)

Json path. See json-query for more usage details.

Examples

Partial deep equal

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

await spec()
  .get('https://reqres.in/api/users/1')
  .expectJsonMatch({
    "data": {
      "first_name": like("George"),
      "last_name": "Bluth"
    }
  });

Using json path

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

await spec()
  .get('https://reqres.in/api/users/1')
  .expectJsonMatch('data.first_name', like('George'));

See Also

Released under the MIT License.