myzod icon indicating copy to clipboard operation
myzod copied to clipboard

Jest toEqual Matcher Doesn't Skip Undefined

Open jteppinette opened this issue 1 year ago • 1 comments

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

jteppinette avatar Jun 01 '23 17:06 jteppinette

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.

davidmdm avatar Jun 03 '23 14:06 davidmdm