@@ -92,52 +92,57 @@ describe('Picker.Panel', () => {
92
92
} ) ;
93
93
94
94
describe ( 'time click to scroll' , ( ) => {
95
- let domSpy : ReturnType < typeof spyElementPrototypes > ;
96
- const requestAnimationFrameSpy = jest . spyOn (
97
- global ,
98
- 'requestAnimationFrame' as any ,
99
- ) ;
100
-
101
- beforeEach ( ( ) => {
102
- let scrollTop = 90 ;
95
+ [ true , false ] . forEach ( bool => {
96
+ it ( `spy requestAnimationFrame: ${ bool } ` , ( ) => {
97
+ let scrollTop = 90 ;
98
+ const domSpy = spyElementPrototypes ( HTMLElement , {
99
+ scrollTop : {
100
+ get : ( ) => scrollTop ,
101
+ set : ( ( _ : Function , value : number ) => {
102
+ scrollTop = value ;
103
+ } ) as any ,
104
+ } ,
105
+ } ) ;
106
+
107
+ let requestAnimationFrameSpy = jest . spyOn (
108
+ global ,
109
+ 'requestAnimationFrame' as any ,
110
+ ) ;
103
111
104
- domSpy = spyElementPrototypes ( HTMLElement , {
105
- scrollTop : {
106
- get : ( ) => scrollTop ,
107
- set : ( ( _ : Function , value : number ) => {
108
- scrollTop = value ;
109
- } ) as any ,
110
- } ,
112
+ // Spy to trigger 2 way of test for checking case cover
113
+ if ( bool ) {
114
+ requestAnimationFrameSpy = requestAnimationFrameSpy . mockImplementation (
115
+ window . setTimeout as any ,
116
+ ) ;
117
+ }
118
+
119
+ jest . useFakeTimers ( ) ;
120
+ const wrapper = mount ( < MomentPickerPanel picker = "time" /> ) ;
121
+
122
+ // Multiple times should only one work
123
+ wrapper
124
+ . find ( 'ul' )
125
+ . first ( )
126
+ . find ( 'li' )
127
+ . at ( 3 )
128
+ . simulate ( 'click' ) ;
129
+
130
+ wrapper
131
+ . find ( 'ul' )
132
+ . first ( )
133
+ . find ( 'li' )
134
+ . at ( 11 )
135
+ . simulate ( 'click' ) ;
136
+ jest . runAllTimers ( ) ;
137
+
138
+ expect ( requestAnimationFrameSpy ) . toHaveBeenCalled ( ) ;
139
+
140
+ jest . useRealTimers ( ) ;
141
+
142
+ domSpy . mockRestore ( ) ;
143
+ requestAnimationFrameSpy . mockRestore ( ) ;
111
144
} ) ;
112
145
} ) ;
113
- afterEach ( ( ) => {
114
- domSpy . mockRestore ( ) ;
115
- } ) ;
116
-
117
- it ( 'scroll' , ( ) => {
118
- jest . useFakeTimers ( ) ;
119
- const wrapper = mount ( < MomentPickerPanel picker = "time" /> ) ;
120
-
121
- // Multiple times should only one work
122
- wrapper
123
- . find ( 'ul' )
124
- . first ( )
125
- . find ( 'li' )
126
- . at ( 3 )
127
- . simulate ( 'click' ) ;
128
-
129
- wrapper
130
- . find ( 'ul' )
131
- . first ( )
132
- . find ( 'li' )
133
- . at ( 11 )
134
- . simulate ( 'click' ) ;
135
- jest . runAllTimers ( ) ;
136
-
137
- expect ( requestAnimationFrameSpy ) . toHaveBeenCalled ( ) ;
138
-
139
- jest . useRealTimers ( ) ;
140
- } ) ;
141
146
} ) ;
142
147
143
148
describe ( 'click button to switch' , ( ) => {
0 commit comments