# Using IF/ELSE in Postman Test scripts

**URL:** <https://community.postman.com/t/using-if-else-in-postman-test-scripts/32164>\
**Category:** Help Hub\
**Tags:** tests, json, if-else\
**Created:** [February 2, 2022, 1:28pm UTC](https://community.postman.com/t/using-if-else-in-postman-test-scripts/32164 "2022-02-02T13:28:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Denesh](https://avatars.discourse-cdn.com/v4/letter/d/bc79bd/32.png) [@Denesh](https://community.postman.com/u/Denesh)\
**Post date:** [February 2, 2022, 1:28pm UTC](https://community.postman.com/t/using-if-else-in-postman-test-scripts/32164/1 "2022-02-02T13:28:51Z")

</div>

I am using Postman in order to test, But I am stuck on using if/else in the scripts.

My goal is to test if a property is visible in the response body. if the property is not there, I want postman to expect it be empty. and move on to the next test. The properties are nested in an array.

This is what I came up with so far:

```auto
//Test of correct sub properties rijbewijs zijn meegestuurd
pm.test("Test if correct sub properties rijbewijs are sent", () => {
    if (pm.expect(matchesVacatures.rijbewijs).to.be.empty);
    else { pm.expect(matchesRijbewijs).to.have.property('codeSoortRijbewijs');}  
});

```

However, the test always “fails” if the array is not empty. How do I go about this, it might be something small that have I placed incorrectly in the test, but I cant quite figure it out.

---

<div class="post-metadata">

**Author:** ![Denesh](https://avatars.discourse-cdn.com/v4/letter/d/bc79bd/32.png) [@Denesh](https://community.postman.com/u/Denesh)\
**Post date:** [February 2, 2022, 4:41pm UTC](https://community.postman.com/t/using-if-else-in-postman-test-scripts/32164/2 "2022-02-02T16:41:32Z")

</div>

Figured it out

```auto

pm.test("Test if correct sub properties rijbewijs are sent", () => {
    if ((matchesVacatures.rijbewijs).length !== 0)
    {pm.expect(matchesVacatures.rijbewijs[0]).to.have.property('codeSoortRijbewijs');}

```
