unexpectedjs/unexpected

Object comparison

Opened this issue · 3 comments

I have been looking for a new assertion library after using the basic Node Assert library. Almost all of my tests involve JSON objects. Being able to do partial tests on specific fields in an object, or deep equals types of checks is imperative.

The very first test I have written, and I don't understand why it is failing:

image

EDIT: It seems the 'to satisfy' command works for this use case. I am still unsure what the difference is between 'to satisfy' and 'to have a value satisfying' when doing a prop/value check?

Yeah, to satisfy is the right assertion to use here. The to have a value satisfying assertion only looks at the values themselves, disregarding the keys of the object. So your object would have a value satisfying 'KBOS' or { latitude: 42.36429977 }, but not { icao: 'KBOS' }. Maybe that's not super obvious from the name of the assertion, though 🤷‍♂️

You can see some examples here: https://unexpected.js.org/assertions/object/to-have-a-value-satisfying/

Hi @chrismbeckett, thank for trying out the library. @papandreou beat me to the explanation :-) to have a value satisfying is mostly useful if you are using objects as maps and are trying to assert that a value with certain criteria is present in the map. This is not something that will be useful that often. Normally to satisfy will be you goto assertion for most things and I think it should fulfil most of the use cases you discribe.

Thank you for the quick reply. I have converted most of my tests to Unexpected now and am very much appreciated the good documentation and straight-forward approach to this assertion library.