Closed alekhinen closed 4 years ago
Hey there, thanks for using Testing Library!
Unfortunately I don’t have time to run/debug this right now, but I think I see the issue. Unlike React/DOM Testing Library, the results of queries saved to variables aren’t live references, only saved instances. Because of that, after you fire the press event, you’ll have to query for the text element again to get the updated text value of 1
.
Hope that helps!
Hey @bcarroll22 thanks for the quick response!
So it turns out that the same code all works when we swapped the import of TouchableOpacity
from the react-native-gesture-handler
to react-native
😓
So making the imports for the above example as the following fixed the issue:
import React, { useState } from 'react';
import { TouchableOpacity, Text, View } from 'react-native';
I'm unfamiliar with the internal mechanics of react-native-gesture-handler
but there is definitely an issue where this testing library's fireEvent()
s do not trigger the event handlers for the components exported from that lib.
react-native
orexpo
: exponative-testing-library
version: 5.0.3jest-preset
: @testing-library/react-nativereact-native
version: 0.61.4node
version: v13.3.0Relevant code or config:
OpacityExample.tsx
OpacityExample.test.tsx
What you did:
My team is working on a feature where we want to increment/decrement an input value via some touchable elements. We've run into an issue where firing a press event doesn't trigger the event handler in this instance – though we've been able to get the
onPress
handler to trigger in other scenarios for some reason. In our codebase, the other workingfireEvent.press()
are being selected viagetByText()
notgetByTestId()
.What happened:
Reproduction:
The above code is all that is needed to repro the issue.
Problem description:
We are assuming that invoking
fireEvent.press(touchableEl)
will trigger that element'sonPress
handler and subsequently increment the value we are rendering out into the JSX tree.Suggested solution:
N/A
Can you help us fix this issue by submitting a pull request?
N/A