@@ -71,22 +71,24 @@ describe('List.Touch', () => {
7171 return wrapper . find ( '.rc-virtual-list-holder' ) . instance ( ) ;
7272 }
7373
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+ } ) ;
9092 expect ( wrapper . find ( 'ul' ) . instance ( ) . scrollTop > 10 ) . toBeTruthy ( ) ;
9193
9294 wrapper . unmount ( ) ;
@@ -99,35 +101,39 @@ describe('List.Touch', () => {
99101 return wrapper . find ( '.rc-virtual-list-holder' ) . instance ( ) ;
100102 }
101103
102- // start
103- const touchEvent = new Event ( 'touchstart' ) ;
104- touchEvent . touches = [ { pageY : 500 } ] ;
105- getElement ( ) . dispatchEvent ( touchEvent ) ;
106-
107- // move
108104 const preventDefault = jest . fn ( ) ;
109- const moveEvent = new Event ( 'touchmove' ) ;
110- moveEvent . touches = [ { pageY : 0 } ] ;
111- moveEvent . preventDefault = preventDefault ;
112- getElement ( ) . dispatchEvent ( moveEvent ) ;
113105
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+ } ) ;
114118 // Call preventDefault
115119 expect ( preventDefault ) . toHaveBeenCalled ( ) ;
116120
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 ( ) ;
120125
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 ) ;
125130
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+ } ) ;
131137
132138 expect ( preventDefault ) . not . toHaveBeenCalled ( ) ;
133139 } ) ;
@@ -137,16 +143,18 @@ describe('List.Touch', () => {
137143 const preventDefault = jest . fn ( ) ;
138144 const wrapper = genList ( { itemHeight : 20 , height : 100 , data : genData ( 100 ) } ) ;
139145
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+ } ) ;
143151
144152 expect ( preventDefault ) . toHaveBeenCalled ( ) ;
145153 } ) ;
146154
147155 it ( 'nest touch' , async ( ) => {
148156 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" >
150158 { ( { id } ) =>
151159 id === '0' ? (
152160 < li >
0 commit comments