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
Any way to get the value of an input/select? #67
Comments
@kwhitaker Though I wouldn't be opposed to adding a |
@lelandrichardson thanks for the tip, but sadly that selector comes up as Here's the full
|
Wait duh. I wasn't explicitly setting |
@lelandrichardson This works well when you want to test that the prop as an argument is correct, but doesn't work well when you are wanting to test the rendered output. In my case, I am auto-formatting a value as part of the render function as part of the implementation of the component. I might be missing something, but when I try to use a const TextInput = ({value, autoformat}) =>
<div>
<input type="text" value={autoformat(value)} />
</div>
const NumberInput = props => <TextInput autoformat={commas} {...props} />
mount(<NumberInput value={1000} />).find('input').html() // <input type="text"/> instead of <input type="text" value="1,000"/>
shallow(<NumberInput value={1000} />).find('input').html() // Error: This method is only meant to be run on single node. 0 found instead In many cases, I'm able to use |
@lelandrichardson Any thoughts on this? |
@ljharb I just wanted to ping you on my question above, since you are the number 2 contributor to the library - is this something we can expect to change? |
@tshelburne what does |
@ljharb Thanks so much for the quick response. I randomly decided to check what version I was on (2.2.0), and then to update to the latest version to run your request, and now this appears to be working. Sorry for the mistake. |
@tshelburne Checking the |
@trusktr Can't disagree with your reasoning from a technical perspective, but when I'm asking my designers / new developers to update and write unit tests for components, it's a much more reasonable expectation for them to compare HTML strings than to consider the underpinnings of React (simple though it may seem). We have a robust pattern library in it's own NPM module that is backed by React components, and it's not intended just to be a JS developer's playground, but something accessible to everyone on the team. I'm all about making systems that enable developers at every level, and being able to reliably check the rendered HTML has already been a meaningfully helpful tool. That said, thanks for the clarification. |
@trusktr My scenario to test, Am I given the right state property name to the input element's value attribute. like, i have my state property name as "firstName", but i specified as |
I think getting it with prop() also makes sense |
I'm trying to make sure that a select box is rendered with the proper value selected. I don't see any hooks into
value
in the docs forshallow
orrender
. Is there an obvious thing I'm missing?The text was updated successfully, but these errors were encountered: