Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document actual behaviour of object (Not) containing #12307

Closed
wants to merge 1 commit into from
Closed

Document actual behaviour of object (Not) containing #12307

wants to merge 1 commit into from

Conversation

Biki-das
Copy link
Contributor

@Biki-das Biki-das commented Feb 6, 2022

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.

@codecov-commenter
Copy link

Codecov Report

Merging #12307 (f4199b9) into main (94a6752) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #12307   +/-   ##
=======================================
  Coverage   67.25%   67.25%           
=======================================
  Files         329      329           
  Lines       17346    17346           
  Branches     5074     5074           
=======================================
  Hits        11666    11666           
  Misses       5648     5648           
  Partials       32       32           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 94a6752...f4199b9. Read the comment docs.

@Biki-das
Copy link
Contributor Author

@SimenB looking forward to your thoughts

@mrazauskas
Copy link
Contributor

Duplicate of #11157

@SimenB SimenB closed this Feb 24, 2022
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

objectContaining not matching valid subset per docs objectContaining should be recursive but isn't
5 participants