RFC: Test selectors - #221
Conversation
| createTestNameSelector('LoginFormButton') | ||
| ``` | ||
|
|
||
| ## `createHasPseudoClassSelector()` |
There was a problem hiding this comment.
Bikeshedding, but this one is the only selector whose name doesn't make intuitive sense to me. Maybe something like could work?createHasContentsSelector
There was a problem hiding this comment.
Actually, I meant to propose createContainsSelector.
There was a problem hiding this comment.
Agreed that the naming of this one is a mouthful. The concept (and so the name) is inspired by CSS pseudo-classes. I don't feel strongly about this name being the one we must have though. The important thing is that the name makes it clear that this one works differently than the others: It doesn't select the element(s) at the end of its nested selectors; it just refines the criteria for where it's at in the higher level selection tree. (These words are not a very clear explanation of what it's doing, sorry.)
There was a problem hiding this comment.
I am not strongly opposed to the name createContainsSelector exactly, but I do worry it's potentially confusable with createTextSelector (since people might think of elements as containing text).
There was a problem hiding this comment.
Are the semantics close enough that we can make them both overloads of createContainsSelector? i.e. pass a string to Contains -> get the Text behaviour. (Then it's a separate design choice whether to keep the Text selector around separately for convenience/readability.)
There was a problem hiding this comment.
I think the closest CSS analogue is :has(), right? So maybe createHasSelector, except that it scans as "has selector" which is awkward. As a compromise from there, createHasElementSelector?
There was a problem hiding this comment.
Last one of this batch of ideas: createHasMatchSelector
There was a problem hiding this comment.
I jokingly mentioned the lookahead name, but there is a pretty strong similarity. Of the names we've discussed, I think maybe that one gives the strongest indicator of what it does / how it works relative to some other established concept.
There was a problem hiding this comment.
My 2 cents on "lookahead", while we're here, is that it may be an established term, but still seems niche / context-specific. It's also more imperative than declarative, if that makes sense: it tells the selector matcher what to do instead of what element to look for.
There was a problem hiding this comment.
In other words, "Lookahead" would be an improvement over "HasPseudoClass" for me as a reader but I'd still worry about it being too opaque to a general audience.
This proposal introduces a set of APIs to help with automated testing of React applications.
View formatted RFC