No handler function found for event: "scroll"
See original GitHub issueDescribe the bug
I was writing tests to see if I could invoke the refreshControl
component on my <ScrollView />
.
When invoking fireEvent.scroll(getByText("foobar"), eventData);
, I get the error No handler function found for event: "scroll"
.
I haven’t defined an onScroll
on my <ScrollView />
component. I shouldn’t need to, it’s an optional parameter for the component.
It’s interesting to see in the docs that a “scroll handler” is mocked.
Expected behavior
I can use a query to select a component on my screen, which exists inside of a <ScrollView />
component and call fireEvent.scroll(queriedComponent, eventData)
.
Steps to Reproduce
// Foobar.tsx - skipped set up code for brevity
const _onRefresh = async () => {
setRefreshing(true);
await someAsyncFunction();
setRefreshing(false);
};
return (
<ScrollView
accessible={false}
refreshControl={
<RefreshControl refreshing={refreshing} onRefresh={_onRefresh} />
}
>
<View>
<Text}>"Foobar"</Text>
</View>
</ScrollView>
);
// Foobar.test.tsx
it("test foobar scroll", async () => {
const { getByText } = await waitFor(() => render(<Foorbar />);
// Scroll Up
const eventData = {
nativeEvent: {
contextOffset: {
y: -200,
},
},
};
const someText = getByText("Foobar");
fireEvent.scroll(someText, eventData); // breaks here
});
then run
yarn test <path-to-test-folder>/Foobar.test.tsx
Screenshots
N/A
Versions
npmPackages:
@testing-library/react-native: ^7.0.2 => 7.1.0
react: 16.13.1 => 16.13.1
react-native: ^0.63.2 => 0.63.3
react-test-renderer: 16.13.1 => 16.13.1
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
No handler function found for event: "scroll" #300 - GitHub
Definitely missing the SideMenuBody component, not sure what's there.
Read more >react native - No handler function found for event: "changeText"
The error occurs because there's no onChangeText callback in your TextInput so there's no handler to call when triggering fireEvent.
Read more >Element: scroll event - Web APIs | MDN
The scroll event fires when an element has been scrolled. To detect when scrolling has completed, see the Element: scrollend event.
Read more >API | React Native Testing Library - Open Source
If you're noticing that components are not being found on a list, even after mocking a scroll event, try changing the initialNumToRender that...
Read more >React-testing-library on scroll debounce test - CodeSandbox
React-testing-library on scroll debounce test by jcousins-ynap using @testing-library/react, debounce, jest-dom, react, react-dom, react-scripts.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The implementation of
fireEvent
is simply quite naive and doesn’t reflect the complexity of React Native’s event system. PRs welcome to improve it 😃fireEvent.scroll
expects that there’s aonScroll
prop attached to the ScrollView (or other components). That’s why it complains about no handler being found.