hossein-zare / react-native-dropdown-picker

A single / multiple, categorizable, customizable, localizable and searchable item picker (drop-down) component for react native which supports both Android & iOS.
https://hossein-zare.github.io/react-native-dropdown-picker-website/
MIT License
970 stars 294 forks source link

testing DropDownPicker using React native testing library causing TypeError: Cannot read properties of null (reading 'measureInWindow') #630

Closed mayankchincholkar closed 1 year ago

mayankchincholkar commented 1 year ago

This is what I am doing in my component <DropDownPicker testID={'testId'} style={styles.dropDown} open={open} value={value} items={items} setOpen={setOpen} setValue={setValue} onSelectItem={(item) => { dispatch(update({ item })) }} setItems={setItems} />

When I am loading this component using RNTL await waitFor(() => renderWithProviders(, {preloadedState}) ); and firing an event to open the dropdown await fireEvent.press(screen.getByTestId('testId')) I see this error

TypeError: Cannot read properties of null (reading 'measureInWindow')

at _yield$Promise (/node_modules/react-native-dropdown-picker/src/components/Picker.js:652:37) at tryCallTwo (/node_modules/promise/lib/core.js:45:5) at doResolve (/node_modules/promise/lib/core.js:200:13) at new Promise (/node_modules/promise/lib/core.js:66:3) at _callee$ (/node_modules/react-native-dropdown-picker/src/components/Picker.js:651:15) at tryCatch (/node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:64:40) at Generator.invoke (/node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:299:22) at Generator.next (/node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:124:21) at asyncGeneratorStep (/node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24) at _next (/node_modules/@babel/runtime/helpers/asyncToGenerator.js:25:9)

can anyone help me with a workaround. I tried spying on useRef to mock the implementation but that does not seem to help

mayankchincholkar commented 1 year ago

managed to solve this with the help of this comment https://github.com/hossein-zare/react-native-dropdown-picker/issues/618#issuecomment-1358605788

sort of a worksaround, but works.