@@ -71,22 +71,24 @@ describe('List.Touch', () => {
71
71
return wrapper . find ( '.rc-virtual-list-holder' ) . instance ( ) ;
72
72
}
73
73
74
- // start
75
- const touchEvent = new Event ( 'touchstart' ) ;
76
- touchEvent . touches = [ { pageY : 100 } ] ;
77
- getElement ( ) . dispatchEvent ( touchEvent ) ;
78
-
79
- // move
80
- const moveEvent = new Event ( 'touchmove' ) ;
81
- moveEvent . touches = [ { pageY : 90 } ] ;
82
- getElement ( ) . dispatchEvent ( moveEvent ) ;
83
-
84
- // end
85
- const endEvent = new Event ( 'touchend' ) ;
86
- getElement ( ) . dispatchEvent ( endEvent ) ;
87
-
88
- // smooth
89
- jest . runAllTimers ( ) ;
74
+ act ( ( ) => {
75
+ // start
76
+ const touchEvent = new Event ( 'touchstart' ) ;
77
+ touchEvent . touches = [ { pageY : 100 } ] ;
78
+ getElement ( ) . dispatchEvent ( touchEvent ) ;
79
+
80
+ // move
81
+ const moveEvent = new Event ( 'touchmove' ) ;
82
+ moveEvent . touches = [ { pageY : 90 } ] ;
83
+ getElement ( ) . dispatchEvent ( moveEvent ) ;
84
+
85
+ // end
86
+ const endEvent = new Event ( 'touchend' ) ;
87
+ getElement ( ) . dispatchEvent ( endEvent ) ;
88
+
89
+ // smooth
90
+ jest . runAllTimers ( ) ;
91
+ } ) ;
90
92
expect ( wrapper . find ( 'ul' ) . instance ( ) . scrollTop > 10 ) . toBeTruthy ( ) ;
91
93
92
94
wrapper . unmount ( ) ;
@@ -99,35 +101,39 @@ describe('List.Touch', () => {
99
101
return wrapper . find ( '.rc-virtual-list-holder' ) . instance ( ) ;
100
102
}
101
103
102
- // start
103
- const touchEvent = new Event ( 'touchstart' ) ;
104
- touchEvent . touches = [ { pageY : 500 } ] ;
105
- getElement ( ) . dispatchEvent ( touchEvent ) ;
106
-
107
- // move
108
104
const preventDefault = jest . fn ( ) ;
109
- const moveEvent = new Event ( 'touchmove' ) ;
110
- moveEvent . touches = [ { pageY : 0 } ] ;
111
- moveEvent . preventDefault = preventDefault ;
112
- getElement ( ) . dispatchEvent ( moveEvent ) ;
113
105
106
+ act ( ( ) => {
107
+ // start
108
+ const touchEvent = new Event ( 'touchstart' ) ;
109
+ touchEvent . touches = [ { pageY : 500 } ] ;
110
+ getElement ( ) . dispatchEvent ( touchEvent ) ;
111
+
112
+ // move
113
+ const moveEvent = new Event ( 'touchmove' ) ;
114
+ moveEvent . touches = [ { pageY : 0 } ] ;
115
+ moveEvent . preventDefault = preventDefault ;
116
+ getElement ( ) . dispatchEvent ( moveEvent ) ;
117
+ } ) ;
114
118
// Call preventDefault
115
119
expect ( preventDefault ) . toHaveBeenCalled ( ) ;
116
120
117
- // ======= Not call since scroll to the bottom =======
118
- jest . runAllTimers ( ) ;
119
- preventDefault . mockReset ( ) ;
121
+ act ( ( ) => {
122
+ // ======= Not call since scroll to the bottom =======
123
+ jest . runAllTimers ( ) ;
124
+ preventDefault . mockReset ( ) ;
120
125
121
- // start
122
- const touchEvent2 = new Event ( 'touchstart' ) ;
123
- touchEvent2 . touches = [ { pageY : 500 } ] ;
124
- getElement ( ) . dispatchEvent ( touchEvent2 ) ;
126
+ // start
127
+ const touchEvent2 = new Event ( 'touchstart' ) ;
128
+ touchEvent2 . touches = [ { pageY : 500 } ] ;
129
+ getElement ( ) . dispatchEvent ( touchEvent2 ) ;
125
130
126
- // move
127
- const moveEvent2 = new Event ( 'touchmove' ) ;
128
- moveEvent2 . touches = [ { pageY : 0 } ] ;
129
- moveEvent2 . preventDefault = preventDefault ;
130
- getElement ( ) . dispatchEvent ( moveEvent2 ) ;
131
+ // move
132
+ const moveEvent2 = new Event ( 'touchmove' ) ;
133
+ moveEvent2 . touches = [ { pageY : 0 } ] ;
134
+ moveEvent2 . preventDefault = preventDefault ;
135
+ getElement ( ) . dispatchEvent ( moveEvent2 ) ;
136
+ } ) ;
131
137
132
138
expect ( preventDefault ) . not . toHaveBeenCalled ( ) ;
133
139
} ) ;
@@ -137,16 +143,18 @@ describe('List.Touch', () => {
137
143
const preventDefault = jest . fn ( ) ;
138
144
const wrapper = genList ( { itemHeight : 20 , height : 100 , data : genData ( 100 ) } ) ;
139
145
140
- const touchEvent = new Event ( 'touchstart' ) ;
141
- touchEvent . preventDefault = preventDefault ;
142
- wrapper . find ( '.rc-virtual-list-scrollbar' ) . instance ( ) . dispatchEvent ( touchEvent ) ;
146
+ act ( ( ) => {
147
+ const touchEvent = new Event ( 'touchstart' ) ;
148
+ touchEvent . preventDefault = preventDefault ;
149
+ wrapper . find ( '.rc-virtual-list-scrollbar' ) . instance ( ) . dispatchEvent ( touchEvent ) ;
150
+ } ) ;
143
151
144
152
expect ( preventDefault ) . toHaveBeenCalled ( ) ;
145
153
} ) ;
146
154
147
155
it ( 'nest touch' , async ( ) => {
148
156
const { container } = render (
149
- < List component = "ul" itemHeight = { 20 } height = { 100 } data = { genData ( 100 ) } >
157
+ < List component = "ul" itemHeight = { 20 } height = { 100 } data = { genData ( 100 ) } itemKey = "id" >
150
158
{ ( { id } ) =>
151
159
id === '0' ? (
152
160
< li >
0 commit comments