API Testing · Middle · Question 4 of 75

How do you validate a response body against a JSON Schema in JavaScript tests?

Show the answer

Correct answer: Compile the schema with a validator like Ajv and check the body

Explanation

Ajv returns validation errors with paths like /items/0/price, which makes failures easy to read.

Further reading

Problem with a question

API Testing · Middle · question 4

Test yourself

Take the API Testing · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz