testing-library / native-testing-library

🐳 Simple and complete React Native testing utilities that encourage good testing practices.
https://native-testing-library.com
MIT License
516 stars 44 forks source link

How test a slider component with drag gesture? #112

Closed daniloab closed 4 years ago

daniloab commented 4 years ago

I need to test a slider component simulating the drag gesture. How can I do this on testing library?

Beside to this, I opened another issue in the repo of the slider component that I use to be setting the testID in the correct component to help me with the test. See it https://github.com/ptomasroos/react-native-multi-slider/issues/172

belgamo commented 4 years ago

I have the same problem here. I tried testing with fireEvent.valueChange because it works with Switch component.

matiasmir commented 4 years ago

Hi! same here, have you found a way to test this?

daniloab commented 4 years ago

Not yet

rwalle61 commented 4 years ago

Hi, not sure if this helps, but for React (non-native) Testing Library I can do:

fireEvent.change(screen.getByRole('slider'), { target: { value: '2' }}) // my slider has min '1' and max '7', hence value '2' makes sense

Though I guess the fireEvent API is different for React Native Testing Library.

(PS I'd love a way to test this behaviour from the user's point of view, such as fireEvent.moveSliderLeft(screen.getByRole('slider'), 2))

thymikee commented 4 years ago

Use the Slider's API and fire appropriate event. FYI, this repository is no longer responsible for this package. See the migration guide to v7.0.