fix(objectContaining): Fixed a bug where ObjectContaining matched with non-object values.#15463
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 |
cpojer
left a comment
There was a problem hiding this comment.
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
objectContainingmethod matches withnon-objectvalues, which is inconsistent. Thanks to @flovouin for finding this bug!This PR fixes: #15420
This PR does the following:
expectis an object.invalidtest cases for the above bug.Test plan
This is the new code I wrote for the
objectContainingimplementation: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: