Reputation: 6956
A function returns an array of objects. When I compare the actual result with an expected result using JSON.stringify
the values are identical. However comparison using should.deep.equal
or _.isEqual
fails. Had anyone encountered such issue?
Upvotes: 1
Views: 843
Reputation: 6956
I've realized what the issue was. It is caused by the fact that JSON.stringify
misses fields with undefined
values. E.g. result of applying JSON.stringify
to the following object {field: 'value', undefinedField: undefined}
is {"field": "value"}
. Hence
JSON.stringify({field: 'value', undefinedField: undefined}) === JSON.stringify({field: 'value'})`
But
{field: 'value', undefinedField: undefined}.should.deep.equal({field: 'value'})
fails
Upvotes: 1