assert: add `matchObjectStrict` and `matchObject`
fixes #50399
What is this PR doing:
- Added 2 new assert functions
matchObjectStrict
&matchObject
- Added tests to check different object types (Feel free to suggest more types to be tested)
- Added a new section in the Assert documentation to explain the usage
The compareBranch
(used by matchObject
) works as follows:
-
matchObject
recursively traverses theactual
objects
,Map
, andSet
and rely ondeepEqual
to compare its values (event across different realms) - N.B.array
are directly compared usingdeepEqual
and will not match if they are from different realms -
if
the value is a plain object then it will retrigger thecompareBranch
from that branch onward -
else
will compare theactual
andexpected
values using the built-inisDeepEqual
orisDeepStrictEqual
based on theloose/strict
param - it compares keys - (using
Reflect.ownKeys()
instead ofObject.keys()
to include symbol properties) - checks for recursive object values