expectJsonSchema
Assert based on JSON schema.
- See json-schema for more usage details.
- Pactum internally uses @exodus/schemasafe to validate the 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"
});