Skip to content

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

@gaetan-yg

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 ?

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