@@ -21,7 +21,10 @@ describe('Segment.io retries 500s and 429', () => {
2121 jest . restoreAllMocks ( )
2222
2323 options = { apiKey : 'foo' }
24- analytics = new Analytics ( { writeKey : options . apiKey } )
24+ analytics = new Analytics (
25+ { writeKey : options . apiKey } ,
26+ { retryQueue : true }
27+ )
2528 segment = await segmentio (
2629 analytics ,
2730 options ,
@@ -149,6 +152,7 @@ describe('retryQueue', () => {
149152 } )
150153
151154 it ( 'Only attempts once if retryQueue is false' , async ( ) => {
155+ jest . useFakeTimers ( { advanceTimers : true } )
152156 analytics = new Analytics (
153157 { writeKey : options . apiKey } ,
154158 { retryQueue : false }
@@ -161,11 +165,12 @@ describe('retryQueue', () => {
161165 await analytics . register ( segment , envEnrichment )
162166
163167 await analytics . track ( 'foo' )
164- await new Promise ( ( resolve ) => setTimeout ( resolve , 1000 ) )
168+ jest . runAllTimers ( )
165169 expect ( fetch ) . toHaveBeenCalledTimes ( 1 )
166170 } )
167171
168- it ( 'Attempts multiple times if retryQueue is not false' , async ( ) => {
172+ it ( 'Attempts multiple times if retryQueue is true' , async ( ) => {
173+ jest . useFakeTimers ( { advanceTimers : true } )
169174 analytics = new Analytics (
170175 { writeKey : options . apiKey } ,
171176 { retryQueue : true }
@@ -178,7 +183,7 @@ describe('retryQueue', () => {
178183 await analytics . register ( segment , envEnrichment )
179184
180185 await analytics . track ( 'foo' )
181- await new Promise ( ( resolve ) => setTimeout ( resolve , 1000 ) )
186+ jest . runAllTimers ( )
182187 expect ( fetch . mock . calls . length ) . toBeGreaterThanOrEqual ( 2 )
183188 } )
184189} )
0 commit comments