How to write a test to check if response does not contain specific value


I want to write some tests to check if the response does not contain a specific value or array or object.

Is it possible to test -ve scenario via postman scripts?


Hi @abhikulkarni.1988 ,

Welcome to the community :clap:

You can use Chai.js, sample use like below :+1:
More than examples are here -->

pm.test('is an Array', () => pm.expect(pm.response.json())'array')'object'))

Thanks for your reply but I am trying to write a test like below but it is not working

pm.test(“Response not to have address”,()=>{

Can you help to correct this?

pm.test("Response not to have address", function () 

You can use the as above, should be instead of to.not.include :+1:

No luck with above solution

The answer you shared already contains the word address. Do you want to assert only for the word “address”? :thinking:

I see!

Word “address” is present in key “email_address” but my test is to check if key “address” is not present.

how to achieve this?

Hello @abhikulkarni.1988 , Welcome to the Community :wave:

So here you are testing that “address” shouldn’t be a part of your response body as a object?

In that case, you can try hasOwnProperty function.

var resp = JSON.parse(responseBody);
if (!resp.hasOwnProperty("address")){
pm.test("Address is not present", () => {

Please try this :slightly_smiling_face: If this doesn’t work, kindly explain your need and share more details.


Thanks your solution worked!

But when the Address is present I want to report that the test failed.

I tried the below options in else block“Address is present”);

pm.test(“Address is present”, function () {

Is there better option than this?

@abhikulkarni.1988, May be you can try this:

pm.test("Address is not present", () => {
    if (!resp.hasOwnProperty("address")) {
    else {'Address is present')

Hope this as per your request, I have modified and so you will get pass or fail in single test cases as you expected.


@bpricilla This worked :+1:

I am very thankful for the solution! :grinning:

1 Like

Glad to hear that :grinning: Happy to help always :+1: