-
-
Notifications
You must be signed in to change notification settings - Fork 44
Provided mocking implementation of ScrollView is incomplete #27
Description
react-native
orexpo
: react-nativenative-testing-library
version: 4.0.2jest-preset
: @testing-library/react-nativereact-native
version: 0.59.8node
version: 8.16.0
Relevant code or config:
// Oversimplifying a bit for this sample
const LongScrollView = () => {
const scrollViewRef = React.createRef();
const scrollToEnd = () => scrollViewRef.current.scrollToEnd()
return (
<ScrollView ref={scrollViewRef}>
<Button onPress={scrollToEnd}><Text>Go to End</Text></Button>
<Text>Very large piece of content</Text>
<Text>EndOfScroll</Text>
</ScrollView>
)
}
test('goes to end on pressing the button', () => {
const { getByText } = render(<LongScrollView />)
const button = getByText('Go to End')
fireEvent.press(button)
expect(getByText('EndOfScroll')).not.toThrowError()
})
What you did:
Try to test user behavior where a ScrollView goes to the end after certain interactions
What happened:
While trying to test a component using the provided jest-preset I'm getting the following error. If I use the react-native preset (or if I remove ScrollView from the coreComponents config for native-testing-library) the error doesn't happen.
TypeError: Cannot read property 'Commands' of undefined
at Component.scrollResponderScrollToEnd (/home/dev/X/node_modules/react-native/Libraries/Components/ScrollResponder.js:465:7)
at Object.scrollResponderScrollToEnd [as scrollToEnd] (/home/dev/X/node_modules/react-native-keyboard-aware-scroll-view/lib/KeyboardAwareHOC.js:274:30)
at Object.scrollToEnd [as onDateChange] (/home/dev/X/App/containers/Profile.tsx:209:26)
Problem description:
The provided ScrollView mock is using the same mockComponent behaviour that all other native components, however the ScrollView is a little different in that the mock provided by react-native itself in their jest-preset refers to its own mock implementation: '../Libraries/Components/ScrollView/mocks/ScrollViewMock',
Suggested solution:
I don't have a suggested solution, except a temporary work-around: comment out ScrollView from the coreComponents configuration until a definitive solution is found.