File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import { OfflineActionQueuedError } from '../offline';
55describe ( 'apiCall' , ( ) => {
66 const originalFetch = global . fetch ;
77 const originalNavigator = global . navigator ;
8+
89 const localStorageMock = ( ( ) => {
910 let store : Record < string , string > = { } ;
1011 return {
@@ -96,12 +97,17 @@ describe('apiCall', () => {
9697 } ) ;
9798
9899 it ( 'does not retry aborted requests' , async ( ) => {
100+ // Use real timers to avoid timeout
101+ vi . useRealTimers ( ) ;
102+
99103 const abortError = new DOMException ( 'The operation was aborted.' , 'AbortError' ) ;
100104 const fetchMock = vi . fn ( ) . mockRejectedValue ( abortError ) ;
101105
102106 global . fetch = fetchMock as typeof fetch ;
103107
104- await expect ( apiCall ( '/health' ) ) . rejects . toMatchObject ( {
108+ await expect (
109+ apiCall ( '/health' , { } , { maxRetries : 0 } ) // prevent retry delays
110+ ) . rejects . toMatchObject ( {
105111 name : 'AbortError' ,
106112 } ) ;
107113 expect ( fetchMock ) . toHaveBeenCalledTimes ( 1 ) ;
@@ -124,4 +130,4 @@ describe('apiCall', () => {
124130 expect ( stored ) . toBeTruthy ( ) ;
125131 expect ( JSON . parse ( stored as string ) ) . toHaveLength ( 1 ) ;
126132 } ) ;
127- } ) ;
133+ } ) ;
You can’t perform that action at this time.
0 commit comments