File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import Onyx from 'react-native-onyx' ;
22import type { OnyxEntry } from 'react-native-onyx' ;
33import SaveResponseInOnyx from '@libs/Middleware/SaveResponseInOnyx' ;
4+ import * as PersistedRequests from '@src/libs/actions/PersistedRequests' ;
45// This import is needed to initialize the Onyx connections that call replaceOptimisticReportWithActualReport
56import '@src/libs/actions/replaceOptimisticReportWithActualReport' ;
67import HttpUtils from '@src/libs/HttpUtils' ;
@@ -21,18 +22,21 @@ Onyx.init({
2122 keys : ONYXKEYS ,
2223} ) ;
2324
24- beforeAll ( ( ) => {
25- global . fetch = TestHelper . getGlobalFetchMock ( ) ;
26- } ) ;
27-
2825beforeEach ( async ( ) => {
2926 await Onyx . clear ( ) ;
3027 await waitForBatchedUpdates ( ) ;
28+ // Explicitly reset PersistedRequests module state (knownRequestIDs, ongoingRequest,
29+ // pendingSaveOperations) which Onyx.clear() alone does not fully reset.
30+ await PersistedRequests . clear ( ) ;
31+ await waitForBatchedUpdates ( ) ;
3132 SequentialQueue . resetQueue ( ) ;
3233 MainQueue . clear ( ) ;
3334 HttpUtils . cancelPendingRequests ( ) ;
3435 NetworkStore . checkRequiredData ( ) ;
3536 await waitForNetworkPromises ( ) ;
37+ // Reassign global.fetch to a fresh mock to clear any leftover mockImplementationOnce
38+ // queue from the previous test. jest.clearAllMocks() only resets call counts, not the queue.
39+ global . fetch = TestHelper . getGlobalFetchMock ( ) ;
3640 jest . clearAllMocks ( ) ;
3741 Request . clearMiddlewares ( ) ;
3842} ) ;
You can’t perform that action at this time.
0 commit comments