Why no .map
?
#24016
Unanswered
bmulholland
asked this question in
Questions and Help
Why no `.map`?
#24016
Replies: 1 comment 2 replies
-
Lodash is bundled with cypress which includes |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Cypress includes no way to map over a list of elements. It's possible to do so, but only with a very roundabout approach: creating an array, doing
.each
, adding each to the array, then returning it at the end.map
is such a typical primitive that its lack of inclusion must be a fundamental choice -- one that isn't documented, as far as I could find. There's not even a discussion about it here already, which makes me feel like I must be missing something incredibly obvious.Why isn't there a map? What are we expected to do instead? Why isn't this explained in the documentation?
Specifically: I have a list of elements I am operating on, and I need to store their IDs in an alias for an assertion later. The IDs are stored in
data-testid
. I get the list of elements, and now I want each attribute -- butinvoke
(silently!) returns only the attribute of the first item. I have to somehow loop over them, and the above workaround is the only choice. There are StackOverflows about this, of course, but the code is fighting so much against the structure of Cypress that something feels off. This is the second time I've run into this obstacle, and each time it's taken me over an hour of banging my head against the wall.Beta Was this translation helpful? Give feedback.
All reactions