# Another assertion test

**URL:** <https://community.postman.com/t/another-assertion-test/23440>\
**Category:** Help Hub\
**Tags:** tests\
**Created:** [May 5, 2021, 7:16pm UTC](https://community.postman.com/t/another-assertion-test/23440 "2021-05-05T19:16:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kite0](https://avatars.discourse-cdn.com/v4/letter/k/bc79bd/32.png) [@kite0](https://community.postman.com/u/kite0)\
**Post date:** [May 5, 2021, 7:16pm UTC](https://community.postman.com/t/another-assertion-test/23440/1 "2021-05-05T19:16:59Z")

</div>

I read alot in the forum in this week but i still struggle with assertion and nested objects. There were good tutorials but i was not able to transfer the knowlage.

I’d like to read the value in the arrays like for accounting and consultation

This is a example of the body response:  
 ![Unbenannt](https://us1.discourse-cdn.com/getpostman/original/3X/d/5/d511a31b6ac9675d06bdf6720db9b09ce1db96b6.png)

The department objects has 8 arrays from 0 to 7.

I wrote a test but its “hardcode” not dynamic if something changes later.  
 ![hardcode](https://us1.discourse-cdn.com/getpostman/original/3X/e/4/e45bc7594861df57bea0261f56ec9d28035afd57.png)

I’d like to find the array by name = “marketing” or other name = “…”

my idea was using this structure which i found in the forum [Assertions for API Test scripts](https://community.postman.com/t/assertions-for-api-test-scripts/8717)

but it didn’t worked for my because in almost all of the 8 arrays is the name key.

```plaintext
      for(let key in jsonData.office){
                    if(jsonData.office[key]. **myproblem** ('name=marketing')){
            accountingValue = jsonData.office[key].name.tasks.accounting;
      }
     }
    pm.test("value of accounting", function(){
      pm.expect(accountingValue).to.eql(false);
      });
```

---

<div class="post-metadata">

**Author:** ![jetison](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/jetison/32/12_2.png) [@jetison](https://community.postman.com/u/jetison)\
**Post date:** [May 5, 2021, 9:24pm UTC](https://community.postman.com/t/another-assertion-test/23440/2 "2021-05-05T21:24:39Z")

</div>

@kite0 - can you use `filter()` or `find()`?

```auto
let marketingDepartment = jsonData.office.department.find(dept => { return dept.name === "marketing" })
let accounting = marketingDepartment.tasks.accounting
```

---

<div class="post-metadata">

**Author:** ![kite0](https://avatars.discourse-cdn.com/v4/letter/k/bc79bd/32.png) [@kite0](https://community.postman.com/u/kite0)\
**Post date:** [May 6, 2021, 12:18pm UTC](https://community.postman.com/t/another-assertion-test/23440/3 "2021-05-06T12:18:33Z")

</div>

Thank you it worked well that way 🙂  
i just i have to make it for each array with find function. think there are diffrent ways but its a good start.

in the test my result is 8 times “passed” like accounting status is false

can i add a comment or description to the “Test Results” ? Now all results look the same for me. I have already set enviorment variables to see if for marketing = accounting status is false etc. but would be nice also see in a quick overview for test results
