-
Notifications
You must be signed in to change notification settings - Fork 273
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 issue of getByDisplayValue not checking TextInputs defaultValue #656
Fix issue of getByDisplayValue not checking TextInputs defaultValue #656
Conversation
src/helpers/getByAPI.js
Outdated
@@ -107,11 +107,10 @@ const getTextInputNodeByPlaceholderText = (node, placeholder) => { | |||
const getTextInputNodeByDisplayValue = (node, value) => { | |||
try { | |||
const { TextInput } = require('react-native'); | |||
const nodeValue = node.props.value || node.props.defaultValue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we want to be explicit here and check if node.props.value === undefined
. Would be great to also have a test for value
being 0 and empty string to test that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
indeed that would be better! which value do we use if value is empty string?
for 0, is is possible that it is the number 0 in an input field ? or will it be "0" ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's always gonna be a string for Text, but the only way to be sure would be to test it. I recall numbers also work here, so the Text component may perform some implicit conversion to string.
Nevertheless, if the value
is ""
the defaultValue is no longer used as the value
is set to not-undefined
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh alright I did not know that, I'll make the changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Flow does not let me put 0 in the value prop of the TextInput, it wants a string. Should I ignore it or do we consider it's fine? (especially since we'll now be checking for undefined and not false values)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to test the number then :)
if the value of TextInput is an empty string, then the TextInput will not use the defaultValue and display the empty string. Our tests now do the same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
Summary
This PR aims to solve this issue. Basically the issue to fix is that the byDisplayValue helpers don't check the defaultValue prop of TextInputs.
Requirements
Test plan