question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

predicate in `filterWhere` and `findWhere` should take index as second parameter

See original GitHub issue

Using 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:closed
  • Created 6 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
ljharbcommented, May 16, 2017

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).

0reactions
ljharbcommented, May 16, 2017

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”.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found