React-native-testing-library: How to invoke `onAccessibilityTap` when testing

Created on 4 Sep 2020  路  2Comments  路  Source: callstack/react-native-testing-library

Ask your Question

I have been trying to trigger a tap event from my tests, the non accessible behaviour comes from a swipe with PanResponder. No there is no onPress on the page, rather we enable the View as a role="button" and add the onAccessibilityTap which tested via screen reader and works as expected.

      <View
        accessible
        accessibilityLabel={a11yLabel}
        onAccessibilityTap={onTapCallback}
        accessibilityRole="button"
      >
          ...
      </View>

I've looked at the docs and I can only see press, scroll, and changeText. Attempting to use it by fireEvent(elemInstance, 'eventName') does not work either for various combinations.

Do we know if this is possible? If so how?

Many thanks!

question

Most helpful comment

You could use fireEvent(elementInstance, 'accessibilityTap');. Event name is built as can be seen here: https://github.com/callstack/react-native-testing-library/blob/master/src/fireEvent.js#L85-L86

All 2 comments

You could use fireEvent(elementInstance, 'accessibilityTap');. Event name is built as can be seen here: https://github.com/callstack/react-native-testing-library/blob/master/src/fireEvent.js#L85-L86

Thanks @RafikiTiki !

Was this page helpful?
0 / 5 - 0 ratings