# Test producing a false pass when response body has a json value equal to something

**URL:** <https://community.postman.com/t/test-producing-a-false-pass-when-response-body-has-a-json-value-equal-to-something/29626>\
**Category:** Help Hub\
**Tags:** tests\
**Created:** [November 11, 2021, 5:01pm UTC](https://community.postman.com/t/test-producing-a-false-pass-when-response-body-has-a-json-value-equal-to-something/29626 "2021-11-11T17:01:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![farahziya](https://avatars.discourse-cdn.com/v4/letter/f/8491ac/32.png) [@farahziya](https://community.postman.com/u/farahziya)\
**Post date:** [November 11, 2021, 5:01pm UTC](https://community.postman.com/t/test-producing-a-false-pass-when-response-body-has-a-json-value-equal-to-something/29626/1 "2021-11-11T17:01:27Z")

</div>

I’m new to Postman so still learning the ropes.

I have a response body which contains the following:  
{

```
"acccIndex": 13640,

"acccAcIndex": 1496270,

"acccDateCreated": "2012-01-13T16:11:35.277",

"acccDateUpdated": "2012-03-22T11:31:14.357",

"acccNotes": ""

```

}

In the test section I’m trying to write a test to check that acccAcIndex is present, I’m not bothered about a value just that that acccAcIndex is present.

Every test I’ve created seems to pass but then when I purposefully make it fail it still passes (add in an extra x after: acccAcIndexx.

I’ve tried the following:  
Note these all purposefully should fail but they pass.  
 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/3/7/37196fb1a37314babbe90f00dc941fb71bbc2ae3.png)

Any help / guidance appreciated.

---

<div class="post-metadata">

**Author:** ![cmnazario](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/cmnazario/32/10207_2.png) [@cmnazario](https://community.postman.com/u/cmnazario)\
**Post date:** [November 11, 2021, 9:56pm UTC](https://community.postman.com/t/test-producing-a-false-pass-when-response-body-has-a-json-value-equal-to-something/29626/2 "2021-11-11T21:56:53Z")

</div>

Hello @farahziya

I’ve never used hasOwnProperty 😅, but you can use the following example to check if the property is returning 👇

```auto
pm.test("Account field exists #test2", function() {

    pm.expect(responseJson).to.have.property('acccIndexx');

});

```

Hope this helps 😁

---

<div class="post-metadata">

**Author:** ![bbahadur](https://avatars.discourse-cdn.com/v4/letter/b/9de053/32.png) [@bbahadur](https://community.postman.com/u/bbahadur)\
**Post date:** [November 12, 2021, 9:00am UTC](https://community.postman.com/t/test-producing-a-false-pass-when-response-body-has-a-json-value-equal-to-something/29626/3 "2021-11-12T09:00:30Z")

</div>

Hey @farahziya, Welcome to the community 🥳 !

I think this solution is similar to what you are looking for. Just tune it according to your requirements.

> [@What is wrong with pm.expect](https://community.postman.com/t/what-is-wrong-with-pm-expect/29334/6):
>
> Hey @hasmukhpatel ! If you want to check if ‘data’ has all properties, you can iterate through each and perform assertion. Here is one way to achieve it: let jsonData = pm.response.json(); console.log(jsonData.data); pm.test("All keys present",()=\>{ \_.each(jsonData.data, (item)=\>{ pm.expect(item.hasOwnProperty('start\_date')).to.be.true; pm.expect(item.hasOwnProperty('score')).to.be.true; pm.expect(item.hasOwnProperty('unit')).to.be.true; pm.expect(item.hasOwnProperty('st…

Hope it helps,  
Good luck!

---

<div class="post-metadata">

**Author:** ![farahziya](https://avatars.discourse-cdn.com/v4/letter/f/8491ac/32.png) [@farahziya](https://community.postman.com/u/farahziya)\
**Post date:** [November 12, 2021, 10:41am UTC](https://community.postman.com/t/test-producing-a-false-pass-when-response-body-has-a-json-value-equal-to-something/29626/4 "2021-11-12T10:41:14Z")

</div>

That works, thanks 🙂

---

<div class="post-metadata">

**Author:** ![farahziya](https://avatars.discourse-cdn.com/v4/letter/f/8491ac/32.png) [@farahziya](https://community.postman.com/u/farahziya)\
**Post date:** [November 12, 2021, 10:42am UTC](https://community.postman.com/t/test-producing-a-false-pass-when-response-body-has-a-json-value-equal-to-something/29626/5 "2021-11-12T10:42:52Z")

</div>

Hey, thanks 🙂  
That works, although it doesn’t quite flow naturally for me so for now I’ll stick to the first one (cmnazario). I will keep yours though as it may prove useful later
