Dear all,
I would like to know if there is a difference between the test to.deep.equal() vs to.equal?
Many thanks,
Nawel
Dear all,
I would like to know if there is a difference between the test to.deep.equal() vs to.equal?
Many thanks,
Nawel
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 @allenheltondev 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 handleNaN
,-0
, and+0
specially to conform to IEEE 754 (soNaN != NaN
, and-0 == +0
);- triple equals (
===
) will do the same comparison as double equals (including the special handling forNaN
,-0
, and+0
) but without type conversion; if the types differ,false
is returned.Object.is
does no type conversion and no special handling forNaN
,-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
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.