question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

No handler function found for event: "scroll"

See original GitHub issue

Describe 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:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
thymikeecommented, Dec 6, 2020

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 😃

1reaction
thymikeecommented, Dec 1, 2020

fireEvent.scroll expects that there’s a onScroll prop attached to the ScrollView (or other components). That’s why it complains about no handler being found.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found