# Need help creating assertions for test

**URL:** <https://community.postman.com/t/need-help-creating-assertions-for-test/19212>\
**Category:** Help Hub\
**Tags:** tests, responseassertion\
**Created:** [January 15, 2021, 3:07pm UTC](https://community.postman.com/t/need-help-creating-assertions-for-test/19212 "2021-01-15T15:07:07Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Straub2148](https://avatars.discourse-cdn.com/v4/letter/s/ecb155/32.png) [@Straub2148](https://community.postman.com/u/Straub2148)\
**Post date:** [January 15, 2021, 3:07pm UTC](https://community.postman.com/t/need-help-creating-assertions-for-test/19212/1 "2021-01-15T15:07:07Z")

</div>

I’m new to Postman and do not have any coding experience. How would I go about creating assertions to verify values for “name”, “latitude”, “upperLimit” and “lowerLimit” in the code below?

{  
“@type”: “AntennaConfig”,  
“id”: “9e22f537-0f68-4caf-9d98-445555578d27”,  
“name”: “RPM\_Antenna\_1”,  
“inService”: true,  
“changeTime”: 0,  
“rfPathDelayNS”: 0,  
“latitude”: 42.321,  
“altitude”: 62.125,  
“longitude”: 105.781,  
“type”: “RPM”,  
“feeds”: ,  
“pedestalConfig”: {  
“id”: “4b25d95d-600e-466f-890f-50e84e292e44”,  
“icdImpl”: “DE-3002”,  
“rotorConfigs”: {  
“EL”: {  
“id”: “804e33c4-d959-425d-becd-fd9c52ded61e”,  
“upperLimit”: 250.0,  
“lowerLimit”: -90.0,  
“installationDate”: null,  
“offset”: 5.0,  
“stowPosition”: 25.0,  
“rotorProperties”: {}  
},

---

<div class="post-metadata">

**Author:** ![allenheltondev](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/allenheltondev/32/31738_2.png) [@allenheltondev](https://community.postman.com/u/allenheltondev)\
**Post date:** [January 17, 2021, 2:43pm UTC](https://community.postman.com/t/need-help-creating-assertions-for-test/19212/2 "2021-01-17T14:43:26Z")

</div>

What kind of assertions do you need? To verify that the values are exactly that? Or do you need to verify just that the fields exist and are of a specific data type?

The simplest form is matching the exact values you have, but it won’t work with other responses (since the values will likely change)

```auto
const jsonData = pm.response.json();
pm.test('Has correct values', function(){
  pm.expect(jsonData).has.property('name', 'RPM_Antenna_1');
  pm.expect(jsonData).has.property('latitude', 42.321);
  pm.expect(jsonData).has.property('upperLimit', 250.0);
  pm.expect(jsonData).has.property('lowerLimit', -90.0);
});

```

Using pm.expect this way will verify that your response has the specific properties with the passed in values.

There are ways you can make this dynamic and richer as time goes on, like parameterizing the variable values, or validating the response against a schema. But just give it time for you to understand the pieces and how everything fits together.

---

<div class="post-metadata">

**Author:** ![Straub2148](https://avatars.discourse-cdn.com/v4/letter/s/ecb155/32.png) [@Straub2148](https://community.postman.com/u/Straub2148)\
**Post date:** [January 19, 2021, 1:23pm UTC](https://community.postman.com/t/need-help-creating-assertions-for-test/19212/3 "2021-01-19T13:23:50Z")

</div>

Thank you, Allen for the response. However, I am encountering the error shown below when running the assertion. Any further help you can provide would be appreciated.

FAIL  
Has correct values | AssertionError: expected { Object (@type, id, …) } to have property ‘upperLimit’

---

<div class="post-metadata">

**Author:** ![allenheltondev](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/allenheltondev/32/31738_2.png) [@allenheltondev](https://community.postman.com/u/allenheltondev)\
**Post date:** [January 19, 2021, 1:31pm UTC](https://community.postman.com/t/need-help-creating-assertions-for-test/19212/4 "2021-01-19T13:31:16Z")

</div>

Does the response have the upperLimit property?

---

<div class="post-metadata">

**Author:** ![Straub2148](https://avatars.discourse-cdn.com/v4/letter/s/ecb155/32.png) [@Straub2148](https://community.postman.com/u/Straub2148)\
**Post date:** [January 19, 2021, 2:28pm UTC](https://community.postman.com/t/need-help-creating-assertions-for-test/19212/5 "2021-01-19T14:28:12Z")

</div>

Yes, the response is what I have in my first question above.

---

<div class="post-metadata">

**Author:** ![JBird20](https://avatars.discourse-cdn.com/v4/letter/j/3d9bf3/32.png) [@JBird20](https://community.postman.com/u/JBird20)\
**Post date:** [January 19, 2021, 9:35pm UTC](https://community.postman.com/t/need-help-creating-assertions-for-test/19212/6 "2021-01-19T21:35:51Z")

</div>

@Straub2148 is this a public facing API that we can use or an internal project? if it’s public facing can we get the URL and the relevant GET/POST information please?

---

<div class="post-metadata">

**Author:** ![JBird20](https://avatars.discourse-cdn.com/v4/letter/j/3d9bf3/32.png) [@JBird20](https://community.postman.com/u/JBird20)\
**Post date:** [January 19, 2021, 9:37pm UTC](https://community.postman.com/t/need-help-creating-assertions-for-test/19212/7 "2021-01-19T21:37:54Z")

</div>

```
{
   "@type":"AntennaConfig",
   "id":“9e22f537-0f68-4caf-9d98-445555578d27”,
   "name":“RPM_Antenna_1”,
   "inService":true,
   "changeTime":0,
   "rfPathDelayNS":0,
   "latitude":42.321,
   "altitude":62.125,
   "longitude":105.781,
   "type":"RPM",
   "feeds":,
   "pedestalConfig":{
      "id":“4b25d95d-600e-466f-890f-50e84e292e44”,
      "icdImpl":“DE-3002”,
      "rotorConfigs":{
         "EL":{
            "id":“804e33c4-d959-425d-becd-fd9c52ded61e”,
            "upperLimit":250.0,
            "lowerLimit":-90.0,
            "installationDate":null,
            "offset":5.0,
            "stowPosition":25.0,
            "rotorProperties":{
               
            }
         },

```

@allenheltondev I could be wrong, but doesn’t the expect have to follow the JSON path down?

e.g.

` pm.expect(jsonData).has.property('pedestalConfig.rotorConfigs.EL.upperLimit', 250.0);`

or

`pm.expect(jsonData. pedestalConfig.rotorConfigs.EL.upperLimit).to.equal(250.0);`

@Straub2148

---

<div class="post-metadata">

**Author:** ![wendy.cook](https://avatars.discourse-cdn.com/v4/letter/w/74df32/32.png) [@wendy.cook](https://community.postman.com/u/wendy.cook)\
**Post date:** [January 19, 2021, 10:41pm UTC](https://community.postman.com/t/need-help-creating-assertions-for-test/19212/8 "2021-01-19T22:41:23Z")

</div>

> `pm.expect(jsonData).has.property('pedestalConfig.rotorConfigs.EL.upperLimit', 250.0);`
> 
> or
> 
> `pm.expect(jsonData. pedestalConfig.rotorConfigs.EL.upperLimit).to.equal(250.0);`

The error for the second case is less clear than in the first, if the property is missing.  
In the first case, it will tell you the property can’t be found.  
In the latter case, it will tell you that undef does not equal 250.0

But basically, yah, you need to add the complete json node path.

```auto
const jsonData = pm.response.json();
pm.test('Has correct values', function(){
  pm.expect(jsonData).has.property('name', 'RPM_Antenna_1');
  pm.expect(jsonData).has.property('latitude', 42.321);
  pm.expect(jsonData).has.property('pedestalConfig.EL.upperLimit', 250.0);
  pm.expect(jsonData).has.property('pedestalConfig.EL.lowerLimit', -90.0);
});

```

---

<div class="post-metadata">

**Author:** ![JBird20](https://avatars.discourse-cdn.com/v4/letter/j/3d9bf3/32.png) [@JBird20](https://community.postman.com/u/JBird20)\
**Post date:** [January 19, 2021, 10:55pm UTC](https://community.postman.com/t/need-help-creating-assertions-for-test/19212/9 "2021-01-19T22:55:19Z")

</div>

@Straub2148 try the above and let us know 🙂

---

<div class="post-metadata">

**Author:** ![allenheltondev](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/allenheltondev/32/31738_2.png) [@allenheltondev](https://community.postman.com/u/allenheltondev)\
**Post date:** [January 20, 2021, 11:41am UTC](https://community.postman.com/t/need-help-creating-assertions-for-test/19212/10 "2021-01-20T11:41:47Z")

</div>

Yup, thanks guys, using dot notation to trace down the nested objects is absolutely the way to go.

I couldn’t tell the objects were nested the way it was pasted in the OP. 🤷‍♂️

---

<div class="post-metadata">

**Author:** ![Straub2148](https://avatars.discourse-cdn.com/v4/letter/s/ecb155/32.png) [@Straub2148](https://community.postman.com/u/Straub2148)\
**Post date:** [January 20, 2021, 12:00pm UTC](https://community.postman.com/t/need-help-creating-assertions-for-test/19212/11 "2021-01-20T12:00:24Z")

</div>

This is an internal project.

---

<div class="post-metadata">

**Author:** ![Straub2148](https://avatars.discourse-cdn.com/v4/letter/s/ecb155/32.png) [@Straub2148](https://community.postman.com/u/Straub2148)\
**Post date:** [January 20, 2021, 12:01pm UTC](https://community.postman.com/t/need-help-creating-assertions-for-test/19212/12 "2021-01-20T12:01:22Z")

</div>

Encountered the error shown below when trying the new assertion.

FAIL  
Has correct values | AssertionError: expected { Object (@type, id, …) } to have property ‘pedestalConfig.EL.upperLimit’

---

<div class="post-metadata">

**Author:** ![JBird20](https://avatars.discourse-cdn.com/v4/letter/j/3d9bf3/32.png) [@JBird20](https://community.postman.com/u/JBird20)\
**Post date:** [January 21, 2021, 9:49am UTC](https://community.postman.com/t/need-help-creating-assertions-for-test/19212/13 "2021-01-21T09:49:07Z")

</div>

@Straub2148 please try what I have put in my post:

`pm.expect(jsonData).has.property('pedestalConfig.rotorConfigs.EL.upperLimit', 250.0);`

That error clearly shows you are missing `.rotorConfigs`

Wendy was confirming my post and is missing this path

Let me know

---

<div class="post-metadata">

**Author:** ![allenheltondev](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/allenheltondev/32/31738_2.png) [@allenheltondev](https://community.postman.com/u/allenheltondev)\
**Post date:** [January 21, 2021, 12:03pm UTC](https://community.postman.com/t/need-help-creating-assertions-for-test/19212/14 "2021-01-21T12:03:00Z")

</div>

Hey @Straub2148 ,

@JBird20 is right on this.

To help you in the future for working with json, if you’re trying to get to a specific value, you need to add a dot every time you see a curly brace “{”

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/6/f/6f88799a39dc8405b4ac60d0916b4ecf61320634.png)  
So for your specific example, the way to get to `upperLimit` is:

```auto
pedestalConfig.rotorConfigs.EL.upperLimit

```

---

<div class="post-metadata">

**Author:** ![Straub2148](https://avatars.discourse-cdn.com/v4/letter/s/ecb155/32.png) [@Straub2148](https://community.postman.com/u/Straub2148)\
**Post date:** [January 21, 2021, 12:29pm UTC](https://community.postman.com/t/need-help-creating-assertions-for-test/19212/15 "2021-01-21T12:29:50Z")

</div>

I’m still encountering the error when using this:

const jsonData = pm.response.json();

pm.test(‘Has correct values’, function(){

pm.expect(jsonData).has.property(‘pedestalConfig.rotorConfigs.EL.upperLimit’, 250.0);

});

Error: Has correct values | AssertionError: expected { Object (@type, id, …) } to have property ‘pedestalConfig.rotorConfigs.EL.upperLimit’
