@@ -5,7 +5,6 @@ import {Text, View} from 'react-native';
5
5
import { Constants } from '../../../helpers' ;
6
6
import Carousel from '../index' ;
7
7
8
-
9
8
const numberOfPagesShown = 5 ;
10
9
const eventData = {
11
10
nativeEvent : {
@@ -46,17 +45,19 @@ describe('Carousel tests', () => {
46
45
</ Page >
47
46
) ) }
48
47
</ Carousel > ) ;
48
+
49
49
component . getByText ( 'Page #0' ) ; // Validates that the text is there
50
50
} ) ;
51
51
52
52
it ( 'should trigger onScroll from the second scroll' , ( ) => {
53
53
const component = render ( < Carousel { ...props } >
54
54
{ map ( [ ...Array ( numberOfPagesShown ) ] , ( _ , index ) => (
55
55
< Page key = { index } >
56
- < Text > Page #{ index } </ Text >
56
+ < Text testID = { `page- ${ index } ` } > Page #{ index } </ Text >
57
57
</ Page >
58
58
) ) }
59
59
</ Carousel > ) ;
60
+
60
61
const scrollView = component . getByTestId ( 'carousel.scrollView' ) ;
61
62
62
63
fireEvent . scroll ( scrollView , eventData ) ; //NOTE: first scroll will no fire onScroll
@@ -70,17 +71,18 @@ describe('Carousel tests', () => {
70
71
const component = render ( < Carousel { ...props } >
71
72
{ map ( [ ...Array ( numberOfPagesShown ) ] , ( _ , index ) => (
72
73
< Page key = { index } >
73
- < Text > Page #{ index } </ Text >
74
+ < Text testID = { `page- ${ index } ` } > Page #{ index } </ Text >
74
75
</ Page >
75
76
) ) }
76
77
</ Carousel > ) ;
78
+
77
79
const scrollView = component . getByTestId ( 'carousel.scrollView' ) ;
78
80
79
81
fireEvent . scroll ( scrollView , eventData ) ; //NOTE: first scroll will no fire onScroll
80
82
fireEvent . scroll ( scrollView , eventData ) ;
81
83
expect ( onChangePageMock ) . not . toHaveBeenCalled ( ) ;
82
-
83
- await new Promise ( ( r ) => setTimeout ( r , 2000 ) ) ;
84
+
85
+ await new Promise ( r => setTimeout ( r , 2000 ) ) ;
84
86
fireEvent ( scrollView , 'onMomentumScrollEnd' , eventData ) ;
85
87
expect ( onChangePageMock ) . toHaveBeenCalled ( ) ;
86
88
expect ( onChangePageMock ) . toHaveBeenCalledWith ( 1 , 0 , { isAutoScrolled : false } ) ;
0 commit comments