@@ -20,7 +20,7 @@ describe("useWithRetry", () => {
20
20
const { result } = renderHook ( ( ) => useWithRetry ( mockFn ) ) ;
21
21
22
22
expect ( result . current . isLoading ) . toBe ( false ) ;
23
- expect ( result . current . retryAt ) . toBe ( undefined ) ;
23
+ expect ( result . current . nextRetryAt ) . toBe ( undefined ) ;
24
24
} ) ;
25
25
26
26
it ( "should execute function successfully on first attempt" , async ( ) => {
@@ -34,7 +34,7 @@ describe("useWithRetry", () => {
34
34
35
35
expect ( mockFn ) . toHaveBeenCalledTimes ( 1 ) ;
36
36
expect ( result . current . isLoading ) . toBe ( false ) ;
37
- expect ( result . current . retryAt ) . toBe ( undefined ) ;
37
+ expect ( result . current . nextRetryAt ) . toBe ( undefined ) ;
38
38
} ) ;
39
39
40
40
it ( "should set isLoading to true during execution" , async ( ) => {
@@ -75,7 +75,7 @@ describe("useWithRetry", () => {
75
75
76
76
expect ( mockFn ) . toHaveBeenCalledTimes ( 1 ) ;
77
77
expect ( result . current . isLoading ) . toBe ( false ) ;
78
- expect ( result . current . retryAt ) . not . toBe ( null ) ;
78
+ expect ( result . current . nextRetryAt ) . not . toBe ( null ) ;
79
79
80
80
// Fast-forward to first retry (1 second)
81
81
await act ( async ( ) => {
@@ -84,7 +84,7 @@ describe("useWithRetry", () => {
84
84
85
85
expect ( mockFn ) . toHaveBeenCalledTimes ( 2 ) ;
86
86
expect ( result . current . isLoading ) . toBe ( false ) ;
87
- expect ( result . current . retryAt ) . not . toBe ( null ) ;
87
+ expect ( result . current . nextRetryAt ) . not . toBe ( null ) ;
88
88
89
89
// Fast-forward to second retry (2 seconds)
90
90
await act ( async ( ) => {
@@ -93,7 +93,7 @@ describe("useWithRetry", () => {
93
93
94
94
expect ( mockFn ) . toHaveBeenCalledTimes ( 3 ) ;
95
95
expect ( result . current . isLoading ) . toBe ( false ) ;
96
- expect ( result . current . retryAt ) . toBe ( undefined ) ;
96
+ expect ( result . current . nextRetryAt ) . toBe ( undefined ) ;
97
97
} ) ;
98
98
99
99
it ( "should continue retrying without limit" , async ( ) => {
@@ -108,7 +108,7 @@ describe("useWithRetry", () => {
108
108
109
109
expect ( mockFn ) . toHaveBeenCalledTimes ( 1 ) ;
110
110
expect ( result . current . isLoading ) . toBe ( false ) ;
111
- expect ( result . current . retryAt ) . not . toBe ( null ) ;
111
+ expect ( result . current . nextRetryAt ) . not . toBe ( null ) ;
112
112
113
113
// Fast-forward through multiple retries to verify it continues
114
114
for ( let i = 1 ; i < 15 ; i ++ ) {
@@ -118,11 +118,11 @@ describe("useWithRetry", () => {
118
118
} ) ;
119
119
expect ( mockFn ) . toHaveBeenCalledTimes ( i + 1 ) ;
120
120
expect ( result . current . isLoading ) . toBe ( false ) ;
121
- expect ( result . current . retryAt ) . not . toBe ( null ) ;
121
+ expect ( result . current . nextRetryAt ) . not . toBe ( null ) ;
122
122
}
123
123
124
124
// Should still be retrying after 15 attempts
125
- expect ( result . current . retryAt ) . not . toBe ( null ) ;
125
+ expect ( result . current . nextRetryAt ) . not . toBe ( null ) ;
126
126
} ) ;
127
127
128
128
it ( "should respect max delay of 10 minutes" , async ( ) => {
@@ -150,7 +150,7 @@ describe("useWithRetry", () => {
150
150
}
151
151
152
152
expect ( mockFn ) . toHaveBeenCalledTimes ( 9 ) ;
153
- expect ( result . current . retryAt ) . not . toBe ( null ) ;
153
+ expect ( result . current . nextRetryAt ) . not . toBe ( null ) ;
154
154
155
155
// The 9th retry should use max delay (600000ms = 10 minutes)
156
156
await act ( async ( ) => {
@@ -159,15 +159,15 @@ describe("useWithRetry", () => {
159
159
160
160
expect ( mockFn ) . toHaveBeenCalledTimes ( 10 ) ;
161
161
expect ( result . current . isLoading ) . toBe ( false ) ;
162
- expect ( result . current . retryAt ) . not . toBe ( null ) ;
162
+ expect ( result . current . nextRetryAt ) . not . toBe ( null ) ;
163
163
164
164
// Continue with more retries at max delay to verify it continues indefinitely
165
165
await act ( async ( ) => {
166
166
jest . advanceTimersByTime ( 600000 ) ;
167
167
} ) ;
168
168
169
169
expect ( mockFn ) . toHaveBeenCalledTimes ( 11 ) ;
170
- expect ( result . current . retryAt ) . not . toBe ( null ) ;
170
+ expect ( result . current . nextRetryAt ) . not . toBe ( null ) ;
171
171
} ) ;
172
172
173
173
it ( "should cancel previous retry when call is invoked again" , async ( ) => {
@@ -184,7 +184,7 @@ describe("useWithRetry", () => {
184
184
185
185
expect ( mockFn ) . toHaveBeenCalledTimes ( 1 ) ;
186
186
expect ( result . current . isLoading ) . toBe ( false ) ;
187
- expect ( result . current . retryAt ) . not . toBe ( null ) ;
187
+ expect ( result . current . nextRetryAt ) . not . toBe ( null ) ;
188
188
189
189
// Call again before retry happens
190
190
await act ( async ( ) => {
@@ -193,7 +193,7 @@ describe("useWithRetry", () => {
193
193
194
194
expect ( mockFn ) . toHaveBeenCalledTimes ( 2 ) ;
195
195
expect ( result . current . isLoading ) . toBe ( false ) ;
196
- expect ( result . current . retryAt ) . toBe ( undefined ) ;
196
+ expect ( result . current . nextRetryAt ) . toBe ( undefined ) ;
197
197
198
198
// Advance time to ensure previous retry was cancelled
199
199
await act ( async ( ) => {
@@ -203,7 +203,7 @@ describe("useWithRetry", () => {
203
203
expect ( mockFn ) . toHaveBeenCalledTimes ( 2 ) ; // Should not have been called again
204
204
} ) ;
205
205
206
- it ( "should set retryAt when scheduling retry" , async ( ) => {
206
+ it ( "should set nextRetryAt when scheduling retry" , async ( ) => {
207
207
mockFn
208
208
. mockRejectedValueOnce ( new Error ( "Failure" ) )
209
209
. mockResolvedValueOnce ( undefined ) ;
@@ -215,21 +215,21 @@ describe("useWithRetry", () => {
215
215
await result . current . call ( ) ;
216
216
} ) ;
217
217
218
- const retryAt = result . current . retryAt ;
219
- expect ( retryAt ) . not . toBe ( null ) ;
220
- expect ( retryAt ) . toBeInstanceOf ( Date ) ;
218
+ const nextRetryAt = result . current . nextRetryAt ;
219
+ expect ( nextRetryAt ) . not . toBe ( null ) ;
220
+ expect ( nextRetryAt ) . toBeInstanceOf ( Date ) ;
221
221
222
- // retryAt should be approximately 1 second in the future
222
+ // nextRetryAt should be approximately 1 second in the future
223
223
const expectedTime = Date . now ( ) + 1000 ;
224
- const actualTime = retryAt ! . getTime ( ) ;
224
+ const actualTime = nextRetryAt ! . getTime ( ) ;
225
225
expect ( Math . abs ( actualTime - expectedTime ) ) . toBeLessThan ( 100 ) ; // Allow 100ms tolerance
226
226
227
227
// Advance past retry time
228
228
await act ( async ( ) => {
229
229
jest . advanceTimersByTime ( 1000 ) ;
230
230
} ) ;
231
231
232
- expect ( result . current . retryAt ) . toBe ( undefined ) ;
232
+ expect ( result . current . nextRetryAt ) . toBe ( undefined ) ;
233
233
} ) ;
234
234
235
235
it ( "should cleanup timer on unmount" , async ( ) => {
@@ -243,7 +243,7 @@ describe("useWithRetry", () => {
243
243
} ) ;
244
244
245
245
expect ( result . current . isLoading ) . toBe ( false ) ;
246
- expect ( result . current . retryAt ) . not . toBe ( null ) ;
246
+ expect ( result . current . nextRetryAt ) . not . toBe ( null ) ;
247
247
248
248
// Unmount should cleanup timer
249
249
unmount ( ) ;
0 commit comments