-
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
Bug: Non-editable TextInputs are updated via fireEvent.changeText() when wrapped within 2 components down #1261
Comments
@ylemberg Thanks for reporting this and providing us with repro repository. RNTL event handling works by trying to simulate how React Native event handling would work and we sometimes have discrepancies as the one you've found. We will try to diagnose it at some stage but it looks like relatively low priority issue that can be worked around by avoiding firing change text events at non-editable TextInputs. |
@mdjastrzebski Thanks for taking a look at the issue. Avoiding firing a change text event at a non-editable TextInput does not work for my use case unfortunately. I have a component that has a form, something like
and would like to test |
If your goal is to verify that user cannot edit either
This uses |
This appears to work for my use case. Needed to add an |
Can you post the query & assertion you are using? |
@ylemberg You seem to be using quite old version of Jest Native. Recent versions of it support 'editable' prop in 'toBeDisabled()' matcher. |
@mdjastrzebski ah yes bumping up my |
@ylemberg Happy New Year to you too! |
This one is pretty tricky. What fireEvent does is that it tries to trigger the given event by calling a specific prop on the element. In your case you're using changeText so it will look for onChangeText prop. Since the TextInput is not editable, it will not trigger on the TextInput but then it tries to trigger on the parent. The mechanism of going up the tree is useful namely for touch events, it's what allows to press a button from a Text within it for instance. This can't be fixed easily or without introducing breaking changes, so using the toBeDisabled matcher is a very good workaround for now I think and in the future we may think about changing the behavior of fireEvent so that some cases can't happen |
This issue has been resolved in v12.1.2 🚀 |
Describe the bug
I have an issue very similar to #476. However this reproduces once the
<TextInput />
is nested within 2 components.I created a Github repo to demonstrate this issue.
Expected behavior
A
<TextInput/>
that is nested within 2 components or more should not have thefireEvent.changeText()
invoke theonChangeText()
callback and the test in the above repo"should not fire on non-editable SecondTextInputWrapper"
should passSteps to Reproduce
yarn install
yarn test
Screenshots
Versions
https://github.com/ylemberg/text-input-spec-example/blob/main/package.json
The text was updated successfully, but these errors were encountered: