@@ -98,20 +98,19 @@ describe('request lib', () => {
9898 describe ( 'path, method, body' , ( ) => {
9999 it ( 'is used to send the request' , async ( ) => {
100100 initUseRequest ( { ...successRequest } ) ;
101- await wait ( 10 ) ;
101+ await wait ( 50 ) ;
102102 expect ( hook . data ) . toBe ( successResponse . data ) ;
103103 } ) ;
104104 } ) ;
105105
106- // FLAKY: https://github.com/elastic/kibana/issues/42561
107- describe . skip ( 'pollIntervalMs' , ( ) => {
106+ describe ( 'pollIntervalMs' , ( ) => {
108107 it ( 'sends another request after the specified time has elapsed' , async ( ) => {
109- initUseRequest ( { ...successRequest , pollIntervalMs : 30 } ) ;
110- await wait ( 5 ) ;
111- sinon . assert . calledOnce ( sendPost ) ;
112-
113- await wait ( 40 ) ;
114- sinon . assert . calledTwice ( sendPost ) ;
108+ initUseRequest ( { ...successRequest , pollIntervalMs : 10 } ) ;
109+ await wait ( 50 ) ;
110+ // We just care that multiple requests have been sent out. We don't check the specific
111+ // timing because that risks introducing flakiness into the tests, and it's unlikely
112+ // we could break the implementation by getting the exact timing wrong.
113+ expect ( sendPost . callCount ) . toBeGreaterThan ( 1 ) ;
115114
116115 // We have to manually clean up or else the interval will continue to fire requests,
117116 // interfering with other tests.
@@ -132,14 +131,14 @@ describe('request lib', () => {
132131 initUseRequest ( { ...successRequest , deserializer } ) ;
133132 sinon . assert . notCalled ( deserializer ) ;
134133
135- await wait ( 5 ) ;
134+ await wait ( 50 ) ;
136135 sinon . assert . calledOnce ( deserializer ) ;
137136 sinon . assert . calledWith ( deserializer , successResponse . data ) ;
138137 } ) ;
139138
140139 it ( 'processes data' , async ( ) => {
141140 initUseRequest ( { ...successRequest , deserializer : ( ) => 'intercepted' } ) ;
142- await wait ( 5 ) ;
141+ await wait ( 50 ) ;
143142 expect ( hook . data ) . toBe ( 'intercepted' ) ;
144143 } ) ;
145144 } ) ;
@@ -152,7 +151,7 @@ describe('request lib', () => {
152151 expect ( hook . isInitialRequest ) . toBe ( true ) ;
153152
154153 hook . sendRequest ( ) ;
155- await wait ( 5 ) ;
154+ await wait ( 50 ) ;
156155 expect ( hook . isInitialRequest ) . toBe ( false ) ;
157156 } ) ;
158157 } ) ;
@@ -162,30 +161,29 @@ describe('request lib', () => {
162161 initUseRequest ( { ...successRequest } ) ;
163162 expect ( hook . isLoading ) . toBe ( true ) ;
164163
165- await wait ( 5 ) ;
164+ await wait ( 50 ) ;
166165 expect ( hook . isLoading ) . toBe ( false ) ;
167166 } ) ;
168167 } ) ;
169168
170169 describe ( 'error' , ( ) => {
171170 it ( 'surfaces errors from requests' , async ( ) => {
172171 initUseRequest ( { ...errorRequest } ) ;
173- await wait ( 10 ) ;
172+ await wait ( 50 ) ;
174173 expect ( hook . error ) . toBe ( errorResponse ) ;
175174 } ) ;
176175
177- // FLAKY: https://github.com/elastic/kibana/issues/42563
178- it . skip ( 'persists while a request is in-flight' , async ( ) => {
176+ it ( 'persists while a request is in-flight' , async ( ) => {
179177 initUseRequest ( { ...errorRequest } ) ;
180- await wait ( 5 ) ;
178+ await wait ( 50 ) ;
181179 hook . sendRequest ( ) ;
182180 expect ( hook . isLoading ) . toBe ( true ) ;
183181 expect ( hook . error ) . toBe ( errorResponse ) ;
184182 } ) ;
185183
186184 it ( 'is undefined when the request is successful' , async ( ) => {
187185 initUseRequest ( { ...successRequest } ) ;
188- await wait ( 10 ) ;
186+ await wait ( 50 ) ;
189187 expect ( hook . isLoading ) . toBe ( false ) ;
190188 expect ( hook . error ) . toBeUndefined ( ) ;
191189 } ) ;
@@ -194,30 +192,28 @@ describe('request lib', () => {
194192 describe ( 'data' , ( ) => {
195193 it ( 'surfaces payloads from requests' , async ( ) => {
196194 initUseRequest ( { ...successRequest } ) ;
197- await wait ( 10 ) ;
195+ await wait ( 50 ) ;
198196 expect ( hook . data ) . toBe ( successResponse . data ) ;
199197 } ) ;
200198
201199 it ( 'persists while a request is in-flight' , async ( ) => {
202200 initUseRequest ( { ...successRequest } ) ;
203- await wait ( 5 ) ;
201+ await wait ( 50 ) ;
204202 hook . sendRequest ( ) ;
205203 expect ( hook . isLoading ) . toBe ( true ) ;
206204 expect ( hook . data ) . toBe ( successResponse . data ) ;
207205 } ) ;
208206
209- // FLAKY: https://github.com/elastic/kibana/issues/42562
210- it . skip ( 'is undefined when the request fails' , async ( ) => {
207+ it ( 'is undefined when the request fails' , async ( ) => {
211208 initUseRequest ( { ...errorRequest } ) ;
212- await wait ( 10 ) ;
209+ await wait ( 50 ) ;
213210 expect ( hook . isLoading ) . toBe ( false ) ;
214211 expect ( hook . data ) . toBeUndefined ( ) ;
215212 } ) ;
216213 } ) ;
217214 } ) ;
218215
219- // FLAKY: https://github.com/elastic/kibana/issues/42225
220- describe . skip ( 'callbacks' , ( ) => {
216+ describe ( 'callbacks' , ( ) => {
221217 describe ( 'sendRequest' , ( ) => {
222218 it ( 'sends the request' , ( ) => {
223219 initUseRequest ( { ...successRequest } ) ;
@@ -227,19 +223,26 @@ describe('request lib', () => {
227223 } ) ;
228224
229225 it ( 'resets the pollIntervalMs' , async ( ) => {
230- initUseRequest ( { ...successRequest , pollIntervalMs : 30 } ) ;
231- await wait ( 5 ) ;
232- sinon . assert . calledOnce ( sendPost ) ;
226+ initUseRequest ( { ...successRequest , pollIntervalMs : 800 } ) ;
227+ await wait ( 200 ) ; // 200ms
228+ hook . sendRequest ( ) ;
229+ expect ( sendPost . callCount ) . toBe ( 2 ) ;
233230
234- await wait ( 20 ) ;
231+ await wait ( 200 ) ; // 400ms
235232 hook . sendRequest ( ) ;
236233
237- // If the request didn't reset the interval, there would have been three requests sent by now.
238- await wait ( 20 ) ;
239- sinon . assert . calledTwice ( sendPost ) ;
234+ await wait ( 200 ) ; // 600ms
235+ hook . sendRequest ( ) ;
236+
237+ await wait ( 200 ) ; // 800ms
238+ hook . sendRequest ( ) ;
239+
240+ await wait ( 200 ) ; // 1000ms
241+ hook . sendRequest ( ) ;
240242
241- await wait ( 20 ) ;
242- sinon . assert . calledThrice ( sendPost ) ;
243+ // If sendRequest didn't reset the interval, the interval would have triggered another
244+ // request by now, and the callCount would be 7.
245+ expect ( sendPost . callCount ) . toBe ( 6 ) ;
243246
244247 // We have to manually clean up or else the interval will continue to fire requests,
245248 // interfering with other tests.
0 commit comments