API Testing · Middle · Question 4 of 75
How do you validate a response body against a JSON Schema in JavaScript tests?
- 1Compare
JSON.stringifyof the body with the schema file - 2Compile the schema with a validator like Ajv and check the body
- 3Send the schema in the request and let the server check it
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.