# Difference between to.deep.equal vs to.equal

**URL:** <https://community.postman.com/t/difference-between-to-deep-equal-vs-to-equal/32170>\
**Category:** Help Hub\
**Tags:** tests\
**Created:** [February 2, 2022, 4:11pm UTC](https://community.postman.com/t/difference-between-to-deep-equal-vs-to-equal/32170 "2022-02-02T16:11:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nawelmele](https://avatars.discourse-cdn.com/v4/letter/n/eb8c5e/32.png) [@nawelmele](https://community.postman.com/u/nawelmele)\
**Post date:** [February 2, 2022, 4:11pm UTC](https://community.postman.com/t/difference-between-to-deep-equal-vs-to-equal/32170/1 "2022-02-02T16:11:52Z")

</div>

Dear all,

I would like to know if there is a difference between the test to.deep.equal() vs to.equal?

Many thanks,

Nawel

---

<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:** [February 3, 2022, 12:35pm UTC](https://community.postman.com/t/difference-between-to-deep-equal-vs-to-equal/32170/2 "2022-02-03T12:35:09Z")

</div>

It has to do with comparing if the objects are literally the same object or if the values are the same.

Check out this [StackOverflow answer](https://stackoverflow.com/a/63249954) that describes it pretty well.

---

<div class="post-metadata">

**Author:** ![praveendvd](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/praveendvd/32/6796_2.png) [@praveendvd](https://community.postman.com/u/praveendvd)\
**Post date:** [February 4, 2022, 10:57am UTC](https://community.postman.com/t/difference-between-to-deep-equal-vs-to-equal/32170/3 "2022-02-04T10:57:08Z")

</div>

Just to add to @allenheltondev answer

postman uses chai assertion

> **[Expect / Should - Chai](https://www.chaijs.com/api/bdd/)**
>
> Chai is a BDD / TDD assertion library for \[node\](http://nodejs.org) and the browser that can be delightfully paired with any javascript testing framework.

Javascript as 3 comparisons mainly ,

== , === and Object.is(obj1,obj2)

> - double equals ( `==` ) will perform a type conversion when comparing two things, and will handle `NaN` , `-0` , and `+0` specially to conform to IEEE 754 (so `NaN != NaN` , and `-0 == +0` );
> - triple equals ( `===` ) will do the same comparison as double equals (including the special handling for `NaN` , `-0` , and `+0` ) but without type conversion; if the types differ, `false` is returned.
> - `Object.is` does no type conversion and no special handling for `NaN` , `-0` , and `+0` (giving it the same behavior as `===` except on those special numeric values).

> **[Equality comparisons and sameness - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness#a_model_for_understanding_equality_comparisons)**
>
> JavaScript provides three different value-comparison operations:

But all these comparisons works only on primitive values (non objects like : **string, number, bigint, boolean, undefined, symbol, and null**.)

For Object , it will consider the reference also , meaning it will check whether the objects have same reference or not else it will equate to false. Hence we cannot use any of the three methods for comparing Objects

So coming back to your question . **pm.expect.equal** does “===” strict equal

> **[Expect / Should - Chai](https://www.chaijs.com/api/bdd/#method_equal)**
>
> Chai is a BDD / TDD assertion library for \[node\](http://nodejs.org) and the browser that can be delightfully paired with any javascript testing framework.

While **deep** recursively checks keys and values instead of object as whole . Meaning it does strict content and validation instead of reference check

---

<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:** [December 12, 2024, 12:55pm UTC](https://community.postman.com/t/difference-between-to-deep-equal-vs-to-equal/32170/4 "2024-12-12T12:55:16Z")

</div>

Closed on December 12, 2024, 12:55pm UTC

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