# Expect array property test failing

**URL:** <https://community.postman.com/t/expect-array-property-test-failing/17579>\
**Category:** Help Hub\
**Created:** [November 10, 2020, 10:34pm UTC](https://community.postman.com/t/expect-array-property-test-failing/17579 "2020-11-10T22:34:59Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![robmcec](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/robmcec/32/5857_2.png) [@robmcec](https://community.postman.com/u/robmcec)\
**Post date:** [November 10, 2020, 10:34pm UTC](https://community.postman.com/t/expect-array-property-test-failing/17579/1 "2020-11-10T22:34:59Z")

</div>

Here’s my repsonse:

```auto
{
    "data": {
        "statusItem": [
            {
                "ID": 53,
                "cost": 0,
                "discountType": 0,
                "discountValue": 0,
                "flags": 96,
                "flags3": 256,
                "flags4": 0,
                "flags5": 0,
                "futureBreakID": 0,
                "group": 4,
                "highlightColor": 0,
                "inActive": 0,
                "miscItemID": 0,
                "name": "Acct Correction",
                "notificationID": 0,
                "overrideRejectMins": false,
                "POReturnReasonID": 0,
                "priority": 0,
                "rejectStatusMins": 0,
                "seqNum1": 0,
                "seqNum2": 8192,
                "userOrGroupID": 0
            }

```

I’m trying to expect that just the property ID is in the response.

When I try this:

```auto
pm.expect(jsonData.data.statusItem[0]).to.include("ID");

```

I get the following error:  
**Test array properties | AssertionError: object tested must be an array, a map, an object, a set, a string, or a weakset, but object given**

This does work

```auto
pm.expect(jsonData.data.statusItem[0]).to.include({"ID":53});

```

I understand that the array contains objects, but I don’t know how to isolate the property in the object.

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [November 10, 2020, 11:05pm UTC](https://community.postman.com/t/expect-array-property-test-failing/17579/2 "2020-11-10T23:05:29Z")

</div>

Is there a reason that you have gone for `include` over something else?

Maybe `keys` or `property` might work better:

```auto
.to.have.property('ID');

```

> **[Expect / Should - Chai](https://www.chaijs.com/api/bdd/#method_property)**

---

<div class="post-metadata">

**Author:** ![robmcec](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/robmcec/32/5857_2.png) [@robmcec](https://community.postman.com/u/robmcec)\
**Post date:** [November 10, 2020, 11:24pm UTC](https://community.postman.com/t/expect-array-property-test-failing/17579/3 "2020-11-10T23:24:22Z")

</div>

Yeah, I found that like 5 minutes ago…

Is there a way to chain those together so it’s kind of like a poor man’s schema validation?

```auto
pm.expect(jsonData.data.statusItem[0]).to.have.property("ID");
pm.expect(jsonData.data.statusItem[0]).to.have.property("cost");

```

Is there a way to make this less verbose?

I’ve tried a few different ways with and and it fails.

Thanks!

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [November 11, 2020, 5:20am UTC](https://community.postman.com/t/expect-array-property-test-failing/17579/4 "2020-11-11T05:20:51Z")

</div>

Have you tried any other method from the chaiJS link, like maybe `keys`:

> **[Expect / Should - Chai](https://www.chaijs.com/api/bdd/#method_keys)**

---

<div class="post-metadata">

**Author:** ![robmcec](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/robmcec/32/5857_2.png) [@robmcec](https://community.postman.com/u/robmcec)\
**Post date:** [November 12, 2020, 5:11pm UTC](https://community.postman.com/t/expect-array-property-test-failing/17579/5 "2020-11-12T17:11:02Z")

</div>

Yes I have.  
This test

```auto
pm.expect(jsonData.data.statusItem[0]).to.have.keys('ID'); 

```

Gives this error

```auto
Test array properties | AssertionError: expected { Object (ID, cost, ...) } to have key 'ID'

```

---

<div class="post-metadata">

**Author:** ![arlem](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/arlem/32/3078_2.png) [@arlem](https://community.postman.com/u/arlem)\
**Post date:** [November 12, 2020, 5:28pm UTC](https://community.postman.com/t/expect-array-property-test-failing/17579/6 "2020-11-12T17:28:42Z")

</div>

@robmcec This should work better:  
` pm.expect(jsonData.data.statusItem[0]).to.have.any.keys('ID');`

If you want to check all properties, you can use `all` instead of `any`.

---

<div class="post-metadata">

**Author:** ![robmcec](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/robmcec/32/5857_2.png) [@robmcec](https://community.postman.com/u/robmcec)\
**Post date:** [November 12, 2020, 5:53pm UTC](https://community.postman.com/t/expect-array-property-test-failing/17579/8 "2020-11-12T17:53:35Z")

</div>

Is there a way to check only some keys?

Say I want to check for only ID and Cost I do this:

```auto
pm.expect(jsonData.data.statusItem[0]).to.have.property("ID");
pm.expect(jsonData.data.statusItem[0]).to.have.property("cost");

```

If I do that with this:

```auto
pm.expect(jsonData.data.statusItem[0]).to.have.any.keys("ID","cost");

```

It works, but so does this:

```auto
pm.expect(jsonData.data.statusItem[0]).to.have.any.keys("ID","adsfasdfasd");

```

Because ID and that’s considered “any”.

Is there a way to say

```auto
pm.expect(jsonData.data.statusItem[0]).to.have."some".keys("ID","cost");

```

I know that syntax is wrong, but “any” keys still only helps me if only one is correct. I need a way to list the keys that I want to check on (not all of them, just some) and return a fail if that key\property doesn’t exist.

Thanks!

---

<div class="post-metadata">

**Author:** ![arlem](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/arlem/32/3078_2.png) [@arlem](https://community.postman.com/u/arlem)\
**Post date:** [November 13, 2020, 2:57pm UTC](https://community.postman.com/t/expect-array-property-test-failing/17579/9 "2020-11-13T14:57:08Z")

</div>

I haven’t tried but looking at the documentation a combination of `include` and `keys` should do the trick! 🙂

I’d also recommend that cheat-sheet, it came in very handy a few times for me:

> <https://gist.github.com/yoavniran/1e3b0162e1545055429e>
