fateh999 / react-native-paper-dropdown

Dropdown using react native paper TextInput and Menu
MIT License
130 stars 74 forks source link

How can i Test React-native-paper-dropdown with jest #14

Closed ankiii16 closed 3 years ago

ankiii16 commented 3 years ago

I cannot event find element with testid or label or anything. Please help me out here.

fateh999 commented 3 years ago

I haven't added testing support in this yet

rodrigoAbril commented 1 year ago

@ankiii16 if you add inputProps={{ testID: "id" }} to the dropdown component you can access the input with jest

if any one else is searching for a solution here is an example of how I managed it:

in the component

    <DropDown
        inputProps={{ testID: "theID" }}
        ... />

and in the test:

    const DropDownInput = component.getByTestId('theID');
    await act(async () => {
      fireEvent.press(DropDownInput);
    });
    await act(async () => {
    // list items do not have a useful identifier and byText wasn't working 
    // ( probably because the text is in a child element and the menuitem holds the 
    // function call )
      const  options = component.getAllByRole("menuitem");
      fireEvent.press(options[1]);
    });