I am sending a request that creates an issue in postman. I get a json data in response and I need to check that this data does not contain specified element. How do I do it in tests?
To confirm that a value is missing from the json response, you can use pm.expect(jsonResponse.value).to.be.undefined
.
Here is the full example:
pm.test("valueThatShouldNotBePresent is missing from the json response", function () {
var jsonData = pm.response.json();
pm.expect(jsonData.valueThatShouldNotBePresent).to.be.undefined;
});
Check out the Test Script Examples .
Also we can do the following:
const jsonData = pm.response.json()
pm.test('Key abc is absent', () => {
pm.expect(jsonData).to.not.have.any.keys('abc')
})
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.