Skip to content

Fire a "swipe" event on a Swipeable component #918

Closed

Description

@gaetan-yg

Ask your Question

I am still quite new to react native and react native testing, so maybe I am missing something.

I have a Swipeable component, something like :

<Swipeable
      ref={swipeableRef}
      renderLeftActions={renderLeftActions}
      renderRightActions={renderRightActions}
      onSwipeableLeftOpen={() => decrease(product)}
      onSwipeableRightOpen={() => increase(product)}
      rightThreshold={70}
      leftThreshold={70}
    >
       <Text style={nameStyle}>{product.name}</Text>
       <Text style={quantityStyle}>{product.quantity}</Text>
 </Swipeable>

I am trying to test that swipe left or right triggers the correct action, however I couldn't find a way to fire a "swipe". I ended firing onswipeableRightOpen ie:

fireEvent(getByText('Bananas'), 'swipeableRightOpen')

This lets me test my action but I am testing an implementation details here, is there a way to fire a "generic" swipe event? similar to what a real user would do ?

Activity

  1. thymikee commented on Feb 16, 2022

    @thymikee
    Member

    There's no generic swipe event unfortunately. We're operating in React renderer and there's multiple way to achieve this. For your case fireEvent(getByText('Bananas'), 'swipeableRightOpen') should be good enough. If you want generic swipe testing, you'll need to use an e2e testing framework, like Detox or Appium

  2. gaetan-yg commented on Feb 20, 2022

    @gaetan-yg
    Author

    Thanks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions