fix: accept empty keys when actual object is empty #1384
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When comparing object keys, the user may happen upon comparing two empty
objects. Before this commit, this would be an error:
This commit makes it legal for
keys
to accept no keys when the actual objectis itself empty.
I happened upon this when generating values in property-based testing. Some
tests had object comparisons as the above, but failed for the empty input,
forcing a dance like this:
There is a negative side to this PR to consider:
keys
will change itsbehaviour depending on the object being inspected. That may be fine or it may be
not, depending on the project's goals.
Another thing to consider is how now there are "two" ways to check if an object
is empty:
expect({}).to.be.empty
expect({}).to.have.all.keys({})
That, I feel, is less of a problem, as there seem to be multiple ways of
achieving the same result elsewhere in the library.
Thanks for your time.