predicate in `filterWhere` and `findWhere` should take index as second parameter
See original GitHub issueUsing component.findWhere(predicateFn)
would be really useful if the second parameter of predicateFn
would be the index.
It is customary in all iterator functions in ES6. For example:
['hello','mr'].find( (_, ind) => ind === 1 ) // return the second element
So in Enzyme, taking all elements starting with the 3rd element from a list could work like this:
domElement.find('.list-item').filterWhere( (_, ind) => ind >= 2 )
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Split a list on an index in Prolog
The second parameter (CompleteList) is the list that the predicate should split on a given index. Parameter 3 and 4 are output parameters...
Read more >find(selector) => ReactWrapper - Enzyme - GitHub Pages
Finds every node in the render tree of the current wrapper that matches the provided selector. Arguments. selector ( EnzymeSelector ): The selector...
Read more >enzyme/mount.md at master - api
filterWhere (predicate) => ReactWrapper. Remove nodes in the current wrapper that do not return true for the provided predicate function. .hostNodes() => ...
Read more >Queryable.Where Method (System.Linq)
Each element's index is used in the logic of the predicate function. ... For these parameters, you can pass in a lambda expression...
Read more >Working with Databases: Query Builder
You must use the array format when selecting a DB expression that contains commas ... $query->where('status=1'); // or use parameter binding to bind...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yes, but in ES6, they’re iterating over a list. In enzyme,
.findWhere
is iterating over a tree - there isn’t a useful index.For the use case you mentioned, you can use
.slice(2)
.You’ll note that the index is provided in the language when iterating over arrays, but that the iterable protocol introduced in ES6 lacks any concept of “index” or “count”.