react-native-picker / picker

Picker is a cross-platform UI component for selecting an item from a list of options.
MIT License
1.47k stars 277 forks source link

Issue with unit testing the component #455

Open alex-mironov opened 1 year ago

alex-mironov commented 1 year ago

I'm using react-native-testing library for testing the app. In scope of the test I need to fill in the form with proper value in this selector. My attempt to do it like this:

      fireEvent(await findByTestId('my-picker', 'onValueChange', 'my-value'))

has failed with error:

    TypeError: Cannot read property 'charAt' of undefined

Is there any reliable way to trigger value change inside of the picker from unit tests?

filipebotti commented 1 year ago

I don't know if you still have the issue, but I was able to solve using this:

const picker = await findByTestId('picker-id');
fireEvent(picker, 'onValueChange', 'my-value');