javascriptreact-nativejestjsexporeact-native-testing-library

How to test React Native Slider


I have worked on a Slider component using React Native Slider. And now I want to test it by simulating the sliding gesture. But according to React Native Testing Library documentation, there are only three gestures which are:

  1. fireEvent.Press
  2. fireEvent.changeText
  3. fireEvent.scroll

Is there anyway to simulate the sliding gesture?


Solution

  • If you want to stick with react native library component testing, try out:

    fireEvent(el, 'rowOpen', eventData);
    // or
    fireEvent(el, 'onRowOpen', eventData);
    

    Source

    This functionality can also be achieved with either Appium or Detox, and would require starting up a simulator or physical device. Both of them, under-the-hood would be using the Native Espresso/XCUITest drivers to achieve this.

    I suggest using Detox, or Appium controlled via WebDriverIO.