Skip to content
On this page

expectJsonSchema

Assert based on JSON schema.

Syntax

js
expectJsonSchema(schema)
expectJson(template-name)
expectJson(file-path)
expectJson(file-name)
expectJsonSchema(path, schema)

Usage

โœ… Correct Usage

js
await spec()
  .get('api/users/1')
  .expectJsonSchema({
    "type": "object"
  });

Arguments

> schema (object)

Json schema.

> path (string)

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

Examples

Normal

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

await spec()
  .get('https://reqres.in/api/users/1')
  .expectJsonSchema({
    "type": "object"
  });

Using json path

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

await spec()
  .get('https://reqres.in/api/users/1')
  .expectJsonMatch('data', {
    "type": "object"
  });

See Also

Released under the MIT License.