Document actual behaviour of object (Not) containing #12307
Closed
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.
This PR would close #11126 and close #10462.
The existing documentation for expect.objectContaining(), expect.not.objectContaining(), and to a lesser degree expect.arrayContaining() and expect.not.arrayContaining() doesn't match their behavior.
In this PR, I documented the actual behavior of these asymmetric matchers on master. As it turns out, the actual behavior of expect.objectContaining() is quite strange. Unfortunately, I don't know what the behavior should be, so I'm submitting this PR as-is rather than opening issues.
Documentation/behavior conflicts and edge cases:
expect.objectContaining(), expect.not.objectContaining() are not recursive
expect.objectContaining() can match primitive values
expect.objectContaining() boxes truthy primitives and doesn't box falsy primitives
expect.arrayContaining([]) can match non-arrays (and in fact matches anything)
expect.not.arrayContaining([]) matches nothing
I recommend not merging this PR and instead deciding what expect.objectContaining() should actually do. I'd be happy to update this to reflect the intended behavior, or someone else could submit a new PR.
Test plan
Several tests were added to cover expect.objectContaining() and expect.not.objectContaining()'s behavior with primitive received values.