Skip to content

assert: add `matchObjectStrict` and `matchObject`

Rodrigo Muino Tomonari requested to merge github/fork/synapse/main into main

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 the actual objects, Map, and Set and rely on deepEqual to compare its values (event across different realms) - N.B. array are directly compared using deepEqual and will not match if they are from different realms
  • if the value is a plain object then it will retrigger the compareBranch from that branch onward
  • else will compare the actual and expected values using the built-in isDeepEqual or isDeepStrictEqual based on the loose/strict param
  • it compares keys - (using Reflect.ownKeys() instead of Object.keys() to include symbol properties)
  • checks for recursive object values

Merge request reports

Loading