-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
objectContaining should be recursive but isn't #10462
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
Comments
PR #10508 should fix this. In the meantime, if you want the
Or, of course, just use |
This issue is stale because it has been open for 1 year with no activity. Remove stale label or comment or this will be closed in 30 days. |
This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Uh oh!
There was an error while loading. Please reload this page.
🐛 Bug Report
I couldn't find a duplicate of this, even though it seems like something that could have come up before. The closest I found was #10186, which is related, but only tangentially.
expect.objectContaining
does not work recursively as docs state.To Reproduce
Here's a small test that will fail:
Expected behavior
The test above should have passed according to the docs.
Link to repl or repo (highly encouraged)
Passing and failing tests here
envinfo
doesn't appear to be environment specific - repl and local machines both reproduce. I can add mine and repl's if it seems to be necessary.
workaround
use
toMatchObject
instead (which incidentally seems to have a nicer api)additional info
If we look at toMatchObject vs objectContaining, the
customTesters
passed to theequals
function differ - it looks liketoMatchObject
is actually true subset equality whereobjectContaining
is only subset equality for the first level in the object - in this loop, recursion isn't happening.Looks like there are two options to fix this: either
objectContaining
can implement a recursiveasymmetricMatch
, or it can share a code path withtoMatchObject
, since the two appear to be trying to accomplish the same goal (unless I'm missing something). The latter seems easier, at least on the surface, but I've not looked into it deeply.It also looks like #10430 could potentially replace this fix, and
objectContaining
could become deprecated in favor oftoMatchObject
.The text was updated successfully, but these errors were encountered: