@@ -8,6 +8,7 @@ import * as SequentialQueue from '../../src/libs/Network/SequentialQueue';
88import * as RequestModule from '../../src/libs/Request' ;
99import type Request from '../../src/types/onyx/Request' ;
1010import type { AnyRequest , ConflictActionData } from '../../src/types/onyx/Request' ;
11+ import type { MockFetch } from '../utils/TestHelper' ;
1112import * as TestHelper from '../utils/TestHelper' ;
1213import waitForBatchedUpdates from '../utils/waitForBatchedUpdates' ;
1314
@@ -16,13 +17,15 @@ const request: Request<'userMetadata'> = {
1617 successData : [ { key : 'userMetadata' , onyxMethod : 'set' , value : { accountID : 1234 } } ] ,
1718 failureData : [ { key : 'userMetadata' , onyxMethod : 'set' , value : { } } ] ,
1819} ;
20+ let mockFetch : MockFetch ;
1921beforeAll ( ( ) => {
2022 Onyx . init ( {
2123 keys : ONYXKEYS ,
2224 } ) ;
2325} ) ;
2426beforeEach ( ( ) => {
25- global . fetch = TestHelper . getGlobalFetchMock ( ) ;
27+ mockFetch = TestHelper . createGlobalFetchMock ( ) ;
28+ global . fetch = mockFetch ;
2629 return Onyx . clear ( )
2730 . then ( ( ) => SequentialQueue . clearQueueFlushedData ( ) )
2831 . then ( waitForBatchedUpdates ) ;
@@ -77,10 +80,9 @@ describe('SequentialQueue', () => {
7780 it ( 'should not block the queue when a disk write fails during persist' , async ( ) => {
7881 // If a conflict-resolution disk write rejects (storage full / corruption), push() must not throw
7982 // or strand isReadyPromise — the request should still flush and waitForIdle() should resolve.
80- const mockedFetch = global . fetch as ReturnType < typeof TestHelper . getGlobalFetchMock > & { pause : ( ) => void ; resume : ( ) => Promise < void > } ;
8183 const originalSet = Onyx . set . bind ( Onyx ) ;
8284
83- mockedFetch . pause ( ) ;
85+ mockFetch . pause ( ) ;
8486 try {
8587 await SequentialQueue . push ( { command : 'OpenReport' } ) ; // occupies ongoingRequest
8688 await waitForBatchedUpdates ( ) ;
@@ -105,7 +107,7 @@ describe('SequentialQueue', () => {
105107 setMock . mockRestore ( ) ;
106108 }
107109 } finally {
108- await mockedFetch . resume ( ) ;
110+ await mockFetch . resume ( ) ;
109111 }
110112
111113 // The queue still drains and READs unblock — a hang here would fail the test by timing out.
@@ -170,8 +172,7 @@ describe('SequentialQueue', () => {
170172 // The conflict checker on push 2 inspects the persisted queue (which excludes the
171173 // ongoing request), so it cannot find a 'ReconnectApp' to replace and falls back
172174 // to 'push'. The new request is therefore added to the queue.
173- const mockedFetch = global . fetch as ReturnType < typeof TestHelper . getGlobalFetchMock > & { pause : ( ) => void ; resume : ( ) => Promise < void > } ;
174- mockedFetch . pause ( ) ;
175+ mockFetch . pause ( ) ;
175176 try {
176177 await SequentialQueue . push ( request ) ;
177178 await waitForBatchedUpdates ( ) ;
@@ -194,13 +195,12 @@ describe('SequentialQueue', () => {
194195 // The new request is in the persisted queue with the expected accountID.
195196 expect ( getAll ( ) . some ( ( r ) => r . data ?. accountID === 56789 ) ) . toBe ( true ) ;
196197 } finally {
197- await mockedFetch . resume ( ) ;
198+ await mockFetch . resume ( ) ;
198199 }
199200 } ) ;
200201
201202 it ( 'should replace request in queue while a similar one is ongoing' , async ( ) => {
202- const mockedFetch = global . fetch as ReturnType < typeof TestHelper . getGlobalFetchMock > & { pause : ( ) => void ; resume : ( ) => Promise < void > } ;
203- mockedFetch . pause ( ) ;
203+ mockFetch . pause ( ) ;
204204 try {
205205 await SequentialQueue . push ( request ) ;
206206 await waitForBatchedUpdates ( ) ;
@@ -234,13 +234,12 @@ describe('SequentialQueue', () => {
234234
235235 expect ( getLength ( ) ) . toBe ( 2 ) ;
236236 } finally {
237- await mockedFetch . resume ( ) ;
237+ await mockFetch . resume ( ) ;
238238 }
239239 } ) ;
240240
241241 it ( 'should replace request in queue while a similar one is ongoing and keep the same index' , async ( ) => {
242- const mockedFetch = global . fetch as ReturnType < typeof TestHelper . getGlobalFetchMock > & { pause : ( ) => void ; resume : ( ) => Promise < void > } ;
243- mockedFetch . pause ( ) ;
242+ mockFetch . pause ( ) ;
244243 try {
245244 // First push moves into `ongoingRequest`; subsequent pushes stack in the queue.
246245 await SequentialQueue . push ( { command : 'OpenReport' } ) ;
@@ -270,7 +269,7 @@ describe('SequentialQueue', () => {
270269 expect ( getOngoingRequest ( ) ?. command ) . toBe ( 'OpenReport' ) ;
271270 expect ( persistedRequests . at ( 0 ) ?. data ?. accountID ) . toBe ( 56789 ) ;
272271 } finally {
273- await mockedFetch . resume ( ) ;
272+ await mockFetch . resume ( ) ;
274273 }
275274 } ) ;
276275
0 commit comments