-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Enhance toHaveProperty() to allow array selection #7284
Comments
Right now you can do: expect(stateData).toHaveProperty(
['attributes', 'all', 0, 'values', 0, 'products'],
[2, 3],
); It's obviously not the same, but possible. I'm open to discussion on whether we want this API or now :) |
@thymikee Thank you for that, I didn't know you could access arrays like that, I was expecting to have to use an ugly set of nested Just checked the docs again and there is indeed an example already, which I missed. Sorry, my mistake. Interestingly, I've been trying to get started with Flow this week, and ran into the issues you reference with lodash right-away. FWIW, I'm more than happy with the array path method for |
Closing then (we have too many issues 😫), but happy to accept a PR implementing that, if anybody is interested :) |
+1 for this, honestly I don't really care about types in this situation of doing a |
🚀 Feature Proposal
Enhance the
.toHaveProperty()
matcher to allow array selection, similar to lodash/get.Motivation
Will allow very easy assertions on very complex objects which contain nested arrays/objects.
Example
Pitch
It's an enhancement to an existing matcher which would allow smaller and cleaner tests when asserting against large and complex objects which contain arrays.
As an enhancement, it wouldn't break any existing functionality.
Would bring the path spec in line with the very popular lodash library.
Would meet many peoples expectations of Jest, as I assumed this is a common task and would already be available.
Notes
If I've missed something and asserting deep properties in objects containing arrays is already easy, then sorry, I'm happy to be pointed in the right direction.
The text was updated successfully, but these errors were encountered: