Skip to content
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

fix(queryAllByAttribute): query input elements with dynamically assigned value #166

Conversation

eunjae-lee
Copy link
Contributor

What: The implementation of queryAllByAttribute has been changed so that it can successfully query input elements with dynamically assigned value.

Why: When value is dynamically assigned to an input, not by an attribute on HTML, queryAllByAttribute won't query that element at the moment.

How: queryAllByAttribute behaves differently when its attribute is equal to "value". I'm not sure if this is the best way to implement this. Feedbacks are welcomed.

Checklist:

  • Documentation
  • Tests
  • Ready to be merged
  • Added myself to contributors table

@eunjae-lee
Copy link
Contributor Author

closes #158

@eunjae-lee
Copy link
Contributor Author

Thoughts? @alexkrolick

@kentcdodds
Copy link
Member

I don't like this. I might be inclined to add a new query called queryByProperty which compares DOM node properties directly rather than getAttribute. I honestly don't really like getting by attributes or properties because those are not typically visible to the end user. Getting by the value property of an input is acceptable though because the value of an input is visible to the user.... Hmmm...

What do you think @alexkrolick?

@sompylasar
Copy link
Collaborator

My two cents: if the goal of this library is to operate like a user viewing the page with eyes or screen reader, the inputs (except of type button and submit) and select should be special cases because their default UI is showing certain state that the test may want to assert on. The gray area is when the default UI is hidden, and most likely there are some other elements that represent the actual UI that the user should look at.

@kentcdodds
Copy link
Member

True. We do have getBySelectText perhaps we should do getByInputText and getByTextAreaText as well?

@sompylasar
Copy link
Collaborator

sompylasar commented Dec 6, 2018

The only reason for querying by attribute is because the attributes are proxies to what the browser displays to the user (there's no good way to query the browser render tree itself and get annotated positioned semantic items out of it).

@alexkrolick
Copy link
Collaborator

Maybe the queries for select value and textarea could be combined with the input query - getByCurrentValue? This would smooth over the select value in the same way React does it.

I think this would work for most use cases because the value property and the DOM attribute are initially in sync when an element is created, and when they are different, the property is what is visually displayed.

https://codepen.io/alexkrolick/pen/NELEKE?editors=1011

@kentcdodds
Copy link
Member

Ok, I'm in favor of that. Let's go ahead and add it and we can add a deprecation message to the README for the getBySelectText. Then we can officially remove it in a future breaking change (when we have sufficient justification to break stuff).

Thanks for the PR anyway @eunjae-lee! Would you be interested in making a PR to add a getByCurrentValue query?

@kentcdodds kentcdodds closed this Dec 7, 2018
@eunjae-lee
Copy link
Contributor Author

Thanks all for the feedbacks. I really love how this conclusion has been made!

@kentcdodds I'm still interested in contributing on this. To make sure, getByCurrentValue will refer to value property or (if not exists) DOM attribute, right?

@kentcdodds
Copy link
Member

I think the property should be sufficient.

@eunjae-lee
Copy link
Contributor Author

Hmm. Although value property hasn't been assigned to the element, if it has DOM attribute, end-user will see it on screen. Shouldn't we get elements like this?

@alexkrolick
Copy link
Collaborator

alexkrolick commented Dec 7, 2018

The value property is initially set to the same thing as the attribute, unless I'm interpreting this wrong (check console) https://codepen.io/alexkrolick/pen/NELEKE?editors=1011

Note that getByCurrentValue should also do what getBySelectText does now, so the same interface can be used for user input.

@eunjae-lee
Copy link
Contributor Author

eunjae-lee commented Dec 7, 2018

@alexkrolick oh you're right. My bad. I'll bring a draft for getByCurrentValue today.

@eunjae-lee eunjae-lee deleted the pr/fix-query-all-by-attribute branch December 7, 2018 01:17
@eunjae-lee eunjae-lee mentioned this pull request Dec 7, 2018
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants