Skip to content

Yup for validating JSON schema. #166

Answered by ASaiAnudeep
b12k asked this question in Q&A
Discussion options

You must be logged in to vote

Hello @b12k, Welcome to PactumJS Discussions.

There are different ways we can bring our own custom assertion mechanisms.

expect

expect method allows us to run some custom code to validate the response.

const { spec } = require('pactum');
const { object, string, number } = require('yup');

const user_schema = object({
  name: string().required(),
  age: number().required().positive().integer()
});

await spec()
  .get('https://randomuser.me/api')
  .expect(ctx => {
    user_schema.validateSync(ctx.res.json);
  });

setJsonSchemaAdapter

setJsonSchemaAdapter allows us to update the inbuilt json schema adapter to use a custom defined adapter. Some additional work needs to be done to properly c…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@b12k
Comment options

Answer selected by b12k
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants