Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

Jest - React-native - how to mock a function in ref property?

$
0
0

Im using a library called 'react-native-actions-sheet', which is basically a drawer/panel component. I use it as follows:

import ActionSheet from 'react-native-actions-sheet';import { ActionSheetRef } from 'react-native-actions-sheet';const MyComponent = () => {  const actionSheetRef = useRef<ActionSheetRef>(null);  useEffect(() => {    actionSheetRef.current?.show();  }, []);  return (<ActionSheet      ref={actionSheetRef}      ...><View testID='viewTestId'>      ...</View</ActionSheet>  )}

actionSheetRef.current?.show() is the function that displays the 'drawer'.If I render MyComponent in my test, 'viewTestId' cannot be found.I cannot seem to find a solution, how would I go on about this?


Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>