# AssertionError: expected ' ' to deeply equal

**URL:** <https://community.postman.com/t/assertionerror-expected-to-deeply-equal/22977>\
**Category:** Help Hub\
**Tags:** tests, variables, collections, json\
**Created:** [April 22, 2021, 12:55pm UTC](https://community.postman.com/t/assertionerror-expected-to-deeply-equal/22977 "2021-04-22T12:55:50Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![jagrutiwani0](https://avatars.discourse-cdn.com/v4/letter/j/7ab992/32.png) [@jagrutiwani0](https://community.postman.com/u/jagrutiwani0)\
**Post date:** [April 22, 2021, 12:55pm UTC](https://community.postman.com/t/assertionerror-expected-to-deeply-equal/22977/1 "2021-04-22T12:55:51Z")

</div>

I’m validating one variable value in the response of Postman.  
Here is my code:  
var jsonArrayData = pm.response.json()

console.log(jsonArrayData[0].fields.externalid);

pm.test("Response body contains "+ jsonArrayData[0].fields.externalid, function(){

```
pm.expect(jsonArrayData[0].fields.externalid).to.eql(pm.collectionVariables.get("Customer_Number_Netsuite"));

```

});

and here is the response:

Response body contains 283670438065 | AssertionError: expected ‘283670438065’ to deeply equal 283670438065

Also, find the screenshot for reference:

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/6/5/65268f44b666969684b960a35185c7f3e218edad.png)

---

<div class="post-metadata">

**Author:** ![bpricilla](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/bpricilla/32/6511_2.png) [@bpricilla](https://community.postman.com/u/bpricilla)\
**Post date:** [April 22, 2021, 2:14pm UTC](https://community.postman.com/t/assertionerror-expected-to-deeply-equal/22977/2 "2021-04-22T14:14:13Z")

</div>

Hi @jagrutiwani0, this error is because you are comparing two different data types. Even the value is same here the data type is different.

So while storing the collection variable you can store using JSON.stringify() method,

else you can convert it to integer like this [post](https://community.postman.com/t/how-can-postman-compare-the-value-of-a-written-variable-with-the-value-from-json/14284/2).

```auto
pm.expect(jsonArrayData[0].fields.externalid).to.eql(parseInt(pm.collectionVariables.get("Customer_Number_Netsuite")));

```

Please try and let me know if this works 😊

---

<div class="post-metadata">

**Author:** ![jagrutiwani0](https://avatars.discourse-cdn.com/v4/letter/j/7ab992/32.png) [@jagrutiwani0](https://community.postman.com/u/jagrutiwani0)\
**Post date:** [April 23, 2021, 5:59am UTC](https://community.postman.com/t/assertionerror-expected-to-deeply-equal/22977/3 "2021-04-23T05:59:15Z")

</div>

Hey, it’s working now. I converted both the variables to Integer. Thanks 🙂

---

<div class="post-metadata">

**Author:** ![jagrutiwani0](https://avatars.discourse-cdn.com/v4/letter/j/7ab992/32.png) [@jagrutiwani0](https://community.postman.com/u/jagrutiwani0)\
**Post date:** [April 23, 2021, 7:29am UTC](https://community.postman.com/t/assertionerror-expected-to-deeply-equal/22977/4 "2021-04-23T07:29:31Z")

</div>

Hi @bpricilla ,

What will I use for the comparison of string values?  
Now I’m getting **Response body contains Company Name asTestAPI49514 | AssertionError: expected ‘TestAPI49514’ to deeply equal undefined error**.

---

<div class="post-metadata">

**Author:** ![bpricilla](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/bpricilla/32/6511_2.png) [@bpricilla](https://community.postman.com/u/bpricilla)\
**Post date:** [April 23, 2021, 8:27am UTC](https://community.postman.com/t/assertionerror-expected-to-deeply-equal/22977/5 "2021-04-23T08:27:17Z")

</div>

@jagrutiwani0 You need to use [JSON.stringify()](https://www.w3schools.com/js/js_json_stringify.asp) method.

But in the above error it states that the variable is undefined.

---

<div class="post-metadata">

**Author:** ![jagrutiwani0](https://avatars.discourse-cdn.com/v4/letter/j/7ab992/32.png) [@jagrutiwani0](https://community.postman.com/u/jagrutiwani0)\
**Post date:** [April 23, 2021, 10:30am UTC](https://community.postman.com/t/assertionerror-expected-to-deeply-equal/22977/6 "2021-04-23T10:30:03Z")

</div>

Hi @bpricilla ,

Thanks for noting it! The issue was with the variables. The same were stored in the environment as well as collection. So removed the one from the environment and keeping those variables in Collection. The assertion is working even without using **JSON.stringify()**

---

<div class="post-metadata">

**Author:** ![bpricilla](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/bpricilla/32/6511_2.png) [@bpricilla](https://community.postman.com/u/bpricilla)\
**Post date:** [April 23, 2021, 1:11pm UTC](https://community.postman.com/t/assertionerror-expected-to-deeply-equal/22977/7 "2021-04-23T13:11:44Z")

</div>

Okay good to know that. All the best 💐 Let us know if you have any other issues.

---

<div class="post-metadata">

**Author:** ![hameethapostman](https://avatars.discourse-cdn.com/v4/letter/h/f6c823/32.png) [@hameethapostman](https://community.postman.com/u/hameethapostman)\
**Post date:** [May 26, 2021, 6:38pm UTC](https://community.postman.com/t/assertionerror-expected-to-deeply-equal/22977/8 "2021-05-26T18:38:07Z")

</div>

```
I am trying to write some tests for Day :08 Run a collection

This is my response body:
{
    "results": [
        {
            "gender": "female",
            "name": {
                "title": "Miss",
                "first": "Louna",
                "last": "Fournier"
           },
            "location": {
                "street": {
                    "number": 7581,
                    "name": "Rue Principale"
                },
                "city": "Villeurbanne",
                "state": "Cher",
                "country": "France",
                "postcode": 30638,
                "coordinates": {
                    "latitude": "-24.9843",
                    "longitude": "43.4648"
                },
                "timezone": {
                    "offset": "-2:00",
                    "description": "Mid-Atlantic"
                }
            },
            "email": "louna.fournier@example.com",
            "login": {
                "uuid": "526cff23-7dbb-484e-a2f5-755666e569e3",
                "username": "yellowfrog507",
                "password": "bugs",
                "salt": "CYRTGp3l",
                "md5": "e1db3a070c437203833aeb489ee03743",
                "sha1": "c06d4a9517092b57bbe1ea090914b77f11d7ab77",
                "sha256": "6d4db16a4a030d9fa56e0695d62178130dc69b2c1124796e04bf6cce347447cb"
            },
            "dob": {
                "date": "1962-10-08T00:07:20.111Z",
                "age": 59
            },
            "registered": {
                "date": "2008-08-08T05:24:26.268Z",
                "age": 13
            },
            "phone": "02-39-34-68-25",
            "cell": "06-12-23-24-24",
            "id": {
                "name": "INSEE",
                "value": "2NNaN79081850 66"
            },
            "picture": {
                "large": "https://randomuser.me/api/portraits/women/36.jpg",
                "medium": "https://randomuser.me/api/portraits/med/women/36.jpg",
                "thumbnail": "https://randomuser.me/api/portraits/thumb/women/36.jpg"
            },
            "nat": "FR"
        }
    ],
    "info": {
        "seed": "ba66a06ae496d715",
        "results": 1,
        "page": 1,
        "version": "1.3"
    }
}

```

and my test is

> ```
> pm.test("Person is Female", () => {
> const responseJson = pm.response.json();
> pm.expect(responseJson.nat).to.eql("FR");
> });
> 
> ```

Error: Person is Female | AssertionError: expected undefined to deeply equal ‘FR’

---

<div class="post-metadata">

**Author:** ![bpricilla](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/bpricilla/32/6511_2.png) [@bpricilla](https://community.postman.com/u/bpricilla)\
**Post date:** [May 27, 2021, 4:07am UTC](https://community.postman.com/t/assertionerror-expected-to-deeply-equal/22977/9 "2021-05-27T04:07:05Z")

</div>

Hello @hameethapostman,

```auto
pm.test("Person is Female", () => {
 const responseJson = pm.response.json();
  pm.expect(responseJson.results[0].nat).to.eql("FR");
});

```

Please try this snippet. undefined means that the element is not reachable, so the path might be wrong.

Just a tip here, you can always print your response in console and see the array structure, else for newbies [this site](https://jsonpathfinder.com/) will be really helpful.

You just need to paste your JSON here and you will get the path as result, like below. I have tried with your JSON response.

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/4/f/4f6670ec603bcd0647fcf003a11cacfba6163910.png)

I hope this will help you better!! All the best 🤗

---

<div class="post-metadata">

**Author:** ![neilstudd](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/neilstudd/32/8213_2.png) [@neilstudd](https://community.postman.com/u/neilstudd)\
**Post date:** [May 27, 2021, 7:51am UTC](https://community.postman.com/t/assertionerror-expected-to-deeply-equal/22977/10 "2021-05-27T07:51:16Z")

</div>

Just to add to @bpricilla’s excellent answer: here’s one thing that won’t cause the test to fail, but (in the real world) might cause you a headache later -

Your test is called **Person is Female** but your assertion is checking the nationality. It’s a good idea to make sure your test names are reflective of what is actually being tested (e.g. **Person is French** ), so that if the test fails, you can more easily debug the problem 🙂

---

<div class="post-metadata">

**Author:** ![hameethapostman](https://avatars.discourse-cdn.com/v4/letter/h/f6c823/32.png) [@hameethapostman](https://community.postman.com/u/hameethapostman)\
**Post date:** [May 27, 2021, 7:35pm UTC](https://community.postman.com/t/assertionerror-expected-to-deeply-equal/22977/11 "2021-05-27T19:35:14Z")

</div>

The solution worked Thanks , I see a different error now.

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/3/9/392cd75c8202bcad6dcdcd14d38540e494bf87f9.png)

---

<div class="post-metadata">

**Author:** ![bpricilla](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/bpricilla/32/6511_2.png) [@bpricilla](https://community.postman.com/u/bpricilla)\
**Post date:** [May 28, 2021, 12:14am UTC](https://community.postman.com/t/assertionerror-expected-to-deeply-equal/22977/12 "2021-05-28T00:14:35Z")

</div>

Hello @hameethapostman ,

I can provide a hint here, please go the Tests tab of the submit request.

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/5/d/5d6850796562311c76b50064989f721189d85a7f.png)

You can locate your failed Test case like above and check into the details if you have done the actions marked inside here. And based on you error message it is pretty straight forward that some query params are missing in above any of the three requests. Please try to go through again the documentation details. You can fix it 😊

---

<div class="post-metadata">

**Author:** ![hameethapostman](https://avatars.discourse-cdn.com/v4/letter/h/f6c823/32.png) [@hameethapostman](https://community.postman.com/u/hameethapostman)\
**Post date:** [May 28, 2021, 2:37pm UTC](https://community.postman.com/t/assertionerror-expected-to-deeply-equal/22977/13 "2021-05-28T14:37:59Z")

</div>

Still unable to find the error, I have set the necessary parameters yet see this error.

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/3/1/31c98278823d045afc43c446a18d109b238bcc95.png)

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/d/8/d8b7432864b779f4cd4872786f426392b175e6cc.png)

---

<div class="post-metadata">

**Author:** ![bpricilla](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/bpricilla/32/6511_2.png) [@bpricilla](https://community.postman.com/u/bpricilla)\
**Post date:** [May 29, 2021, 1:15am UTC](https://community.postman.com/t/assertionerror-expected-to-deeply-equal/22977/14 "2021-05-29T01:15:52Z")

</div>

@hameethapostman Please check the URL in the second screen shot, it should only be ‘fr’ and not ‘FR’ 🙂

---

<div class="post-metadata">

**Author:** ![hameethapostman](https://avatars.discourse-cdn.com/v4/letter/h/f6c823/32.png) [@hameethapostman](https://community.postman.com/u/hameethapostman)\
**Post date:** [May 29, 2021, 7:06am UTC](https://community.postman.com/t/assertionerror-expected-to-deeply-equal/22977/15 "2021-05-29T07:06:21Z")

</div>

@bpricilla I did have only FR in the url first ,then I thought may be it is looking for both upper and lowercase and changed it, but still no luck. Don’t know where I am missing it.

These are the scripts I have written for all the three tests

 ![2021-05-29_12h35_17](https://us1.discourse-cdn.com/getpostman/original/3X/b/4/b41ccf38feacadefad378c8f3dfea12c66af85e5.png)  
 ![2021-05-29_12h35_28](https://us1.discourse-cdn.com/getpostman/original/3X/b/d/bd621484679770e0136ddc78fd659f5519a58a62.png)  
 ![2021-05-29_12h35_38](https://us1.discourse-cdn.com/getpostman/original/3X/7/1/7136b7613c799432c6cf166af6ed39256719c006.png)

Requests added correctly | AssertionError: check gender param key: expected ‘nat’ to equal ‘gender’

---

<div class="post-metadata">

**Author:** ![bpricilla](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/bpricilla/32/6511_2.png) [@bpricilla](https://community.postman.com/u/bpricilla)\
**Post date:** [May 29, 2021, 9:32am UTC](https://community.postman.com/t/assertionerror-expected-to-deeply-equal/22977/16 "2021-05-29T09:32:58Z")

</div>

@hameethapostman ,

A general suggestion here, whenever you are stuck-up first thing would be to start over the documentation and read word by word in a fresh mindset 😊 Trust me this worked for me many times.  
Because sometimes a small typo will be killiing our time 😅

So in your case, please go and read your documentation again!

![image](https://us1.discourse-cdn.com/getpostman/original/3X/7/3/73bc5f39b00ddca8afe008d283480b77a18fc06b.png)

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/a/4/a42a127ce98c281cd82cebcd46feb56eb5a9b7a4.png)

Your response should have the nat as ‘FR’ and the URL should have in lower case like in the documentation.

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/1/7/173987182a7a06522b3326bea4bb1d1cebe03552.png)

I hope this helps 😊

---

<div class="post-metadata">

**Author:** ![hameethapostman](https://avatars.discourse-cdn.com/v4/letter/h/f6c823/32.png) [@hameethapostman](https://community.postman.com/u/hameethapostman)\
**Post date:** [May 29, 2021, 5:24pm UTC](https://community.postman.com/t/assertionerror-expected-to-deeply-equal/22977/17 "2021-05-29T17:24:53Z")

</div>

Thanks @bpricilla rereading documentation several times worked for me. The actual problem was the order of parameters in the third request was wrong

Actual : [https://randomuser.me/api/?nat=fr&gender=female](https://randomuser.me/api/?nat=fr&gender=female)

Expected was to assert that the user was a female first and then nationality was French.  
[https://randomuser.me/api/?gender=female&nat=fr](https://randomuser.me/api/?gender=female&nat=fr)

---

<div class="post-metadata">

**Author:** ![bpricilla](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/bpricilla/32/6511_2.png) [@bpricilla](https://community.postman.com/u/bpricilla)\
**Post date:** [May 30, 2021, 12:33am UTC](https://community.postman.com/t/assertionerror-expected-to-deeply-equal/22977/18 "2021-05-30T00:33:05Z")

</div>

@hameethapostman , the order of the params shouldn’t matter here. Both of them should be working and return the same results.

---

<div class="post-metadata">

**Author:** ![Raja2242](https://avatars.discourse-cdn.com/v4/letter/r/2acd7d/32.png) [@Raja2242](https://community.postman.com/u/Raja2242)\
**Post date:** [July 2, 2021, 7:04am UTC](https://community.postman.com/t/assertionerror-expected-to-deeply-equal/22977/19 "2021-07-02T07:04:30Z")

</div>

Hey, I am getting the similar kind of error for below code

```auto
pm.globals.set('respb', pm.response.json());

if (!Object.is(pm.globals.get('respb'), pm.globals.get('respa'))) {

    const result = diff(pm.globals.get('respb'), pm.globals.get('respa'));

    console.log(result);

    pm.test('Difference' + JSON.stringify(result), () => {

    pm.expect(0).to.equal(pm.globals.get(1));

    //pm.expect(0).to.equal(parseInt(pm.globals.get(1)));

});

}

```

 ![image](https://us1.discourse-cdn.com/getpostman/original/2X/b/bdb9e776d595ff29259d741bf99a4d850a7d0495.png)

Can someone help me on this?  
Thanks in advance.

---

<div class="post-metadata">

**Author:** ![moorthiraj](https://avatars.discourse-cdn.com/v4/letter/m/7ab992/32.png) [@moorthiraj](https://community.postman.com/u/moorthiraj)\
**Post date:** [July 4, 2021, 10:51am UTC](https://community.postman.com/t/assertionerror-expected-to-deeply-equal/22977/20 "2021-07-04T10:51:40Z")

</div>

Hi @Raja2242

You have to assert using “eql” as below,

pm.expect(0).to.eql(pm.globals.get(1));

[Next page](https://community.postman.com/t/assertionerror-expected-to-deeply-equal/22977.md?page=2)
