# Check that there is no environment variable inside the response

**URL:** <https://community.postman.com/t/check-that-there-is-no-environment-variable-inside-the-response/27253>\
**Category:** Help Hub\
**Tags:** tests, automation, testscripts, test, negative-testing\
**Created:** [August 29, 2021, 5:27am UTC](https://community.postman.com/t/check-that-there-is-no-environment-variable-inside-the-response/27253 "2021-08-29T05:27:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![science-architect-96](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@science-architect-96](https://community.postman.com/u/science-architect-96)\
**Post date:** [August 29, 2021, 5:27am UTC](https://community.postman.com/t/check-that-there-is-no-environment-variable-inside-the-response/27253/1 "2021-08-29T05:27:00Z")

</div>

To test this section I have to check an Environment Variable that is not inside this reponse  
My response is here

```auto
{
    "status": "ok",
    "statusCode": "0000",
    "message": {
        "text": "",
        "type": ""
    },
    "errors": [],
    "data": {
        "docs": [
            {
                "name": "admin",
                "description": "نقش admin کل سیستم. با دسترسی به همه‌ی بخش ها (System generated)",
                "code": "T11AsR",
                "permissions": [
                    "authenticated",
                    "manage_users",
                    "view_user_logs",
                    "manage_role",
                    "map_role_to_user",
                    "managing_custom_page",
                    "managing_FAQ_page",
                    "managing_jobs_page",
                    "managing_about_us_page",
                    "send_sms",
                    "read_sms",
                    "send_email",
                    "read_email",
                    "manage_system_settings",
                    "manage_profile",
                    "manage_account",
                    "manage_images",
                    "manage_videos",
                    "verify_email",
                    "manage_country_province_city",
                    "manage_resumes",
                    "get_user_report"
                ],
                "protected": true,
                "userType": "admin",
                "_id": "60b2607d6a286901dffe61fa"
            },
            {
                "name": "public",
                "description": "دسترسی های این نقش برای همه کاربران ثبت نام شده و احراز هویت شده مجاز است.",
                "code": "fh1xqE",
                "permissions": [
                    "authenticated",
                    "manage_profile",
                    "manage_account",
                    "verify_email"
                ],
                "protected": true,
                "userType": "client",
                "_id": "60b2607f6a286901dffe61fb"
            }
        ],
        "totalDocs": 2,
        "limit": 100,
        "totalPages": 1,
        "page": 1,
        "pagingCounter": 1,
        "hasPrevPage": false,
        "hasNextPage": false,
        "prevPage": null,
        "nextPage": null
    }
}

```

My environment variable name is “new role code”  
I just need to check that this is not inside the response  
In addition, all this work is to be done in the test section in postman

And I want to check the code property

---

<div class="post-metadata">

**Author:** ![pranavdavar](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/pranavdavar/32/9152_2.png) [@pranavdavar](https://community.postman.com/u/pranavdavar)\
**Post date:** [August 29, 2021, 7:04am UTC](https://community.postman.com/t/check-that-there-is-no-environment-variable-inside-the-response/27253/2 "2021-08-29T07:04:38Z")

</div>

HI @science-architect-96,

You can extract all values of code in a separate array(Variable **code** ) using the map function or for loop.

Then assert the output array not to include value stored in an environment variable(Variable **envVar** ).

`pm.expect(code).to.include(env)`

Hope this helps 🙂

---

<div class="post-metadata">

**Author:** ![science-architect-96](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@science-architect-96](https://community.postman.com/u/science-architect-96)\
**Post date:** [August 29, 2021, 7:07am UTC](https://community.postman.com/t/check-that-there-is-no-environment-variable-inside-the-response/27253/4 "2021-08-29T07:07:58Z")

</div>

i should check that code property shouldnt have my envirment variable  
i dont know the code

---

<div class="post-metadata">

**Author:** ![pranavdavar](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/pranavdavar/32/9152_2.png) [@pranavdavar](https://community.postman.com/u/pranavdavar)\
**Post date:** [August 29, 2021, 7:10am UTC](https://community.postman.com/t/check-that-there-is-no-environment-variable-inside-the-response/27253/5 "2021-08-29T07:10:29Z")

</div>

> [@science-architect-96](#):
>
> new role code

I have created a test code based on your inputs. You may try the below code

```auto
var res = pm.response.json();

console.log(res.data.docs);

var code = res.data.docs.map((doc)=>{

    return doc.code;

});

console.log(code);

var envVar=pm.environment.get('new role code');

pm.test("Your test name", function () {

    var jsonData = pm.response.json();

    pm.expect(code).not.to.include(envVar);

});

```

---

<div class="post-metadata">

**Author:** ![science-architect-96](https://avatars.discourse-cdn.com/v4/letter/s/82dd89/32.png) [@science-architect-96](https://community.postman.com/u/science-architect-96)\
**Post date:** [August 29, 2021, 7:59am UTC](https://community.postman.com/t/check-that-there-is-no-environment-variable-inside-the-response/27253/8 "2021-08-29T07:59:03Z")

</div>

can this code be correct ?

var Data = pm.response.json();

if (pm.response.code === 200) {

```
pm.test("Role deleted", function () {

    var RoleCodes = _.map(Data.data.docs, _.property("code"));

    pm.expect(RoleCodes).not.to.include(pm.environment.get("new role code"));

    postman.setNextRequest("Create user");

});

```

}

else {

```
var errors = _.map(Data.errors, _.property("message"));

console.log(errors);

postman.setNextRequest(null);

```

}
