Difference between to.deep.equal vs to.equal

Dear all,

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

Many thanks,


1 Like

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 that describes it pretty well.

Just to add to @allen.helton answer

postman uses chai assertion

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).

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

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

1 Like