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

Mock component function using react-native testing library

$
0
0

I am writing test case for the first time.

For scrollView, I want to mock onScrollBeginDrag

I have written this code for now

it('Scrolling to third profile adds border radius to image circle of second profile',  () => {  const eventData = {    nativeEvent: {      contentOffset: {y: 1387, x: 0},      contentSize: {width: 414, height: 19423},      layoutMeasurement: {width: 414, height: 693.5}    },  };  const {getByTestId} = render(<Home />)  const scrollView = getByTestId('ProfileVertical')  fireEvent.scroll(getByTestId('ProfileVertical'), eventData);  expect(getByTestId('image-circle-0')).toHaveStyle({ borderColor: '#81D4FA' });})

Here, Home is the parent which contains of another component say scroll which contains of scrollview component.

The scrollView performs changes in context api onScroll and also triggers changes in other scrollView.

My goal in test is to perform onScrollBeginDrag.

How can I do it?


Viewing all articles
Browse latest Browse all 6287

Trending Articles



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