# AssertionError: expected undefined to deeply equal

**URL:** <https://community.postman.com/t/assertionerror-expected-undefined-to-deeply-equal/62296>\
**Category:** Help Hub\
**Tags:** tests, json\
**Created:** [June 17, 2024, 12:20pm UTC](https://community.postman.com/t/assertionerror-expected-undefined-to-deeply-equal/62296 "2024-06-17T12:20:03Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![cryosat-cosmonaut-38](https://avatars.discourse-cdn.com/v4/letter/c/439d5e/32.png) [@cryosat-cosmonaut-38](https://community.postman.com/u/cryosat-cosmonaut-38)\
**Post date:** [June 17, 2024, 12:20pm UTC](https://community.postman.com/t/assertionerror-expected-undefined-to-deeply-equal/62296/1 "2024-06-17T12:20:03Z")

</div>

Can you tell me what is wrong ?  
in pre-req it is written

```auto
pm.environment.set("valueOfMsg", "Request Successfully Executed");

```

in post-res

```auto
pm.test("Check the value of the message parameter:" + pm.environment.get("valueOfMsg"), function () {
  var jsonData = pm.response.json();
  pm.expect(jsonData.message).to.eql(pm.environment.get("valueOfMsg"));

```

> error Checking the value of the parameter message:Request Successfully Executed | AssertionError: expected undefined to deeply equal ‘Request Successfully Executed’

---

<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:** [June 17, 2024, 2:12pm UTC](https://community.postman.com/t/assertionerror-expected-undefined-to-deeply-equal/62296/2 "2024-06-17T14:12:42Z")

</div>

Hey @cryosat-cosmonaut-38 👋

Welcome to the Postman Community! :postman:

You will need to provide some contextual information here, in order for folks to know what this relates to. 🙏

---

<div class="post-metadata">

**Author:** ![cryosat-cosmonaut-38](https://avatars.discourse-cdn.com/v4/letter/c/439d5e/32.png) [@cryosat-cosmonaut-38](https://community.postman.com/u/cryosat-cosmonaut-38)\
**Post date:** [June 17, 2024, 6:11pm UTC](https://community.postman.com/t/assertionerror-expected-undefined-to-deeply-equal/62296/3 "2024-06-17T18:11:48Z")

</div>

snippet doesn’t work, considering it’s written correctly (

---

<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:** [June 17, 2024, 6:18pm UTC](https://community.postman.com/t/assertionerror-expected-undefined-to-deeply-equal/62296/4 "2024-06-17T18:18:51Z")

</div>

> [@danny-dainton](#):
>
> You will need to provide some contextual information here, in order for folks to know what this relates to.

Is this for some training you’re taking? Something else? Are there links to that, that you can provide?

What are the responses of those requests that you’re testing against? Are there any snippets, codeblocks or screenshots that you can provide?

Basically, this `jsonData.message` is _undefined_ so check what that value is. The Postman Console can help here.

You need to assume that no one else can see or has any knowledge of what you have in front of you - over share all the information and build a picture of the issue is so that people can help you.

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [June 18, 2024, 1:15pm UTC](https://community.postman.com/t/assertionerror-expected-undefined-to-deeply-equal/62296/5 "2024-06-18T13:15:17Z")

</div>

> [@cryosat-cosmonaut-38](#):
>
> `jsonData.message`

This is producing the “undefined” error. Get used to console logging the elements you are trying to target. Start by console logging the whole response, and then target each element one level at a time until you get to the key/value you want to actually assert. The usual issue here is data within arrays.

Without seeing an example response. We can’t help you here.

---

<div class="post-metadata">

**Author:** ![cryosat-cosmonaut-38](https://avatars.discourse-cdn.com/v4/letter/c/439d5e/32.png) [@cryosat-cosmonaut-38](https://community.postman.com/u/cryosat-cosmonaut-38)\
**Post date:** [June 18, 2024, 2:33pm UTC](https://community.postman.com/t/assertionerror-expected-undefined-to-deeply-equal/62296/6 "2024-06-18T14:33:12Z")

</div>

I’m sorry, I’m still too stupid in this area)  
I have screenshots from which I rewrote the code.

 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/f/2/f20ee1e9d7e75e862fb9dba402f4f430bdcba47a.png)  
 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/f/c/fc53605a336687c916cac546a7dcf37b9394d37f.png)  
 ![image](https://us1.discourse-cdn.com/getpostman/original/3X/3/1/31b078c0b1e6a79532facec7e35bc040b8401572.png)  
I rewrote everything exactly, but unfortunately the test failed.

---

<div class="post-metadata">

**Author:** ![cryosat-cosmonaut-38](https://avatars.discourse-cdn.com/v4/letter/c/439d5e/32.png) [@cryosat-cosmonaut-38](https://community.postman.com/u/cryosat-cosmonaut-38)\
**Post date:** [June 18, 2024, 2:34pm UTC](https://community.postman.com/t/assertionerror-expected-undefined-to-deeply-equal/62296/7 "2024-06-18T14:34:29Z")

</div>

and this

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

---

<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:** [June 18, 2024, 2:58pm UTC](https://community.postman.com/t/assertionerror-expected-undefined-to-deeply-equal/62296/8 "2024-06-18T14:58:01Z")

</div>

This shows that the test passed. 🤔

---

<div class="post-metadata">

**Author:** ![cryosat-cosmonaut-38](https://avatars.discourse-cdn.com/v4/letter/c/439d5e/32.png) [@cryosat-cosmonaut-38](https://community.postman.com/u/cryosat-cosmonaut-38)\
**Post date:** [June 18, 2024, 4:04pm UTC](https://community.postman.com/t/assertionerror-expected-undefined-to-deeply-equal/62296/9 "2024-06-18T16:04:31Z")

</div>

Yes, but if I copy this snippet my test fails( and I can’t understand why as the code is identical

---

<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:** [June 18, 2024, 4:11pm UTC](https://community.postman.com/t/assertionerror-expected-undefined-to-deeply-equal/62296/10 "2024-06-18T16:11:53Z")

</div>

What’s returned in the the response body?

 ![Screenshot 2024-06-18 at 17.07.46](https://us1.discourse-cdn.com/getpostman/original/3X/1/9/190de37737d68253af58ee438034c317500f9a37.png)

You’re asserting against that value - What value is in the response body for the `message` property? Is it the same for every response?

Is the structure correct? For the way you’re referencing it, it would need to be like this (Other properties might also be there):

```auto
{
    "message": "<The value you are asserting against>"
}

```

---

<div class="post-metadata">

**Author:** ![cryosat-cosmonaut-38](https://avatars.discourse-cdn.com/v4/letter/c/439d5e/32.png) [@cryosat-cosmonaut-38](https://community.postman.com/u/cryosat-cosmonaut-38)\
**Post date:** [June 18, 2024, 5:29pm UTC](https://community.postman.com/t/assertionerror-expected-undefined-to-deeply-equal/62296/11 "2024-06-18T17:29:12Z")

</div>

I can’t know this as the homework only includes screenshots and parsing of these snippets .  
If you write value in the body, the test will still fail. I want to figure out why this happens, I have tried everything I can.

---

<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:** [June 18, 2024, 6:46pm UTC](https://community.postman.com/t/assertionerror-expected-undefined-to-deeply-equal/62296/12 "2024-06-18T18:46:17Z")

</div>

I think you’re better off asking who ever set that _homework_, for more information if you don’t understand what they want you to do.

We still haven’t see what the response body for that request looks like - the test is testing that. It’s testing whatever is returned in the `message` property, matches that variable value.

There is a lot of contextual information here that you’re not sharing which makes it impossible for anyone to actually provide you with a solution.

---

<div class="post-metadata">

**Author:** ![cryosat-cosmonaut-38](https://avatars.discourse-cdn.com/v4/letter/c/439d5e/32.png) [@cryosat-cosmonaut-38](https://community.postman.com/u/cryosat-cosmonaut-38)\
**Post date:** [June 18, 2024, 6:49pm UTC](https://community.postman.com/t/assertionerror-expected-undefined-to-deeply-equal/62296/13 "2024-06-18T18:49:36Z")

</div>

I can’t show the body because the job is an early version of postman and it has a different interface.

I can send you the json and you can have a look )

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [July 18, 2024, 6:50pm UTC](https://community.postman.com/t/assertionerror-expected-undefined-to-deeply-equal/62296/14 "2024-07-18T18:50:18Z")

</div>

Closed on July 18, 2024, 6:50pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
