I have an API that does not omit JSON serialization for fields with "empty" (null, none, nil) values and returns all of them as "fieldName": null. I have typed DTOs in testing code (TypeScript), and I would like to make such fields as optional (?) and leave them undefined in many places. Unfortunately (for me) jest's toEqual() treats undefined (values in testing code) and null (values from API) as different values.
My current solution is to use union types like string | null, but it is pretty verbose, because I have to always initialize those fields.
I checked jest's reference and did not find an "off-the-shelf" solution. So, creation a custom matcher is the only way to solve my problem?
Note: I can't change policy of serialization in API.