Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions tests/unit/MiddlewareTest.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Onyx from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
import SaveResponseInOnyx from '@libs/Middleware/SaveResponseInOnyx';
import * as PersistedRequests from '@src/libs/actions/PersistedRequests';
// This import is needed to initialize the Onyx connections that call replaceOptimisticReportWithActualReport
import '@src/libs/actions/replaceOptimisticReportWithActualReport';
import HttpUtils from '@src/libs/HttpUtils';
Expand All @@ -21,18 +22,21 @@ Onyx.init({
keys: ONYXKEYS,
});

beforeAll(() => {
global.fetch = TestHelper.getGlobalFetchMock();
});

beforeEach(async () => {
await Onyx.clear();
await waitForBatchedUpdates();
// Explicitly reset PersistedRequests module state (knownRequestIDs, ongoingRequest,
// pendingSaveOperations) which Onyx.clear() alone does not fully reset.
await PersistedRequests.clear();
await waitForBatchedUpdates();
SequentialQueue.resetQueue();
MainQueue.clear();
HttpUtils.cancelPendingRequests();
NetworkStore.checkRequiredData();
await waitForNetworkPromises();
// Reassign global.fetch to a fresh mock to clear any leftover mockImplementationOnce
// queue from the previous test. jest.clearAllMocks() only resets call counts, not the queue.
global.fetch = TestHelper.getGlobalFetchMock();
jest.clearAllMocks();
Request.clearMiddlewares();
});
Expand Down
Loading