-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
fix(objectContaining): Fixed a bug where ObjectContaining matched with non-object values. #15463
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
Conversation
…t matched with non-object values.
✅ Deploy Preview for jestjs ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify site configuration. |
@mohammednumaan I'm not a maintainer of jest, just a contributor - sorry ^^ |
This PR is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 30 days. |
not stale |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Facebook is gonna have fun upgrading to Jest 30.
When trying to upgrade my team to v30 I found this bug was being used in asymetric matching to assert on the array length. I couldn't see an alternative approach now that this has been fixed. For example, this used to pass, but now fails when trying to assert on the length of expect(testFunc).toHaveBeenLastCalledWith(
expect.objectContaining({
someArray: expect.arrayContaining([
expect.objectContaining({
list: expect.objectContaining({ length: 2 }),
}),
]),
}),
); My workaround has been to switch to an array filled with an expect(testFunc).toHaveBeenLastCalledWith(
expect.objectContaining({
someArray: expect.arrayContaining([
expect.objectContaining({
list: new Array(2).fill(expect.anything())
}),
]),
}),
); |
I think it is valid solution. |
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. |
Summary
The
objectContaining
method matches withnon-object
values, which is inconsistent. Thanks to @flovouin for finding this bug!This PR fixes: #15420
This PR does the following:
expect
is an object.invalid
test cases for the above bug.Test plan
This is the new code I wrote for the
objectContaining
implementation:This is the new test cases I wrote for verifying the above added code works:
To run the tests, I ran the following command:
The test results: