myzod
myzod copied to clipboard
Jest toEqual Matcher Doesn't Skip Undefined
The result of myzod causes Jest's .toEqual
's skipping of undefined keys to not work. I am assuming this is due to some prototype hacking?
i.e.
expect({a: undefined}).toEqual({}) // pass
expect(<same result from myzod).toEqual({}) // fail
Workaround
I am able to resolve this by recreating the object via JSON.parse/stringify:
expect(JSON.parse(JSON.stringify(result))).toEqual({}) // pass
There is no prototype hacking in myzod. Sometimes myzod will create a new object if it's necessary, such as when coercion is used between numbers and strings and dates, or when "map" is invoked on a schema.
Perhaps this has to do with deep equality?
Myzod does not do anything esoteric to objects or their prototypes.