Closed bgneu closed 4 years ago
Closing this issue, because as I debugged a bit more the issue is with the Touchable components themselves. In order to get the press fireEvent to work we have to mock TouchableOpacity
(see https://github.com/testing-library/native-testing-library/issues/113#issuecomment-607796505), however once mocked, attempting to get a reference to the component does not work, which then snowballs into the issue that caused me to create this ticket.
A work around that's working for me now is
jest.mock('react-native/Libraries/Components/Touchable/TouchableOpacity', () => {
const TouchableOpacity = jest.requireActual(
'react-native/Libraries/Components/Touchable/TouchableOpacity',
)
TouchableOpacity.displayName = 'TouchableOpacity';
return TouchableOpacity;
});
@bgneu thanks, you saved me
react-native
orexpo
: react-nativenative-testing-library
version: 5.0.3jest-preset
: @testing-library/react-native/jest-presetreact-native
version: 0.62.2node
version: 14.4.0Relevant code or config:
this._button
is a ref toTouchableOpacity
component.What you did:
Upgraded existing project from RN 0.61.5, where I had this reported issue, to 0.62.2.
With the upgrade, however, it seems like the mock-native-methods are no longer accessible because on close inspection
this._button.measure === null
returns true on tests. This is also true for the other native methods.What happened:
The
measure
function is not available, therefore not being called.Reproduction:
I'll try to update the issue with a repo that reproduces the issue.
Problem description:
The
measure
method, along with all other native methods mentioned in RN docs should be available on most of the default components provided by React Native.Suggested solution:
Attempted to look into the
@testing-library/react-native
preset code, but could not spend too much time as to come up with a solution or improvement.Can you help us fix this issue by submitting a pull request?
Would love to, but I have some other work priorities which may not allow me to devote the needed time to fix this. If it changes before this is resolved I'll definitely look into it.