Skip to content

Commit 981b112

Browse files
authored
Merge pull request Expensify#66182 from nkdengineer/fix/66037
[No QA] Fix flaky test UnreadIndicatorsTest
2 parents 4d7d44a + 6af72ce commit 981b112

3 files changed

Lines changed: 5 additions & 2 deletions

File tree

src/libs/actions/IOU.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2533,6 +2533,7 @@ function buildOnyxDataForTrackExpense({
25332533
onyxMethod: Onyx.METHOD.MERGE,
25342534
key: `${ONYXKEYS.COLLECTION.REPORT}${chatReport.reportID}`,
25352535
value: {
2536+
lastReadTime: actionableTrackExpenseWhisper.created,
25362537
lastVisibleActionCreated: actionableTrackExpenseWhisper.created,
25372538
lastMessageText: CONST.ACTIONABLE_TRACK_EXPENSE_WHISPER_MESSAGE,
25382539
},

tests/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
- Much of the logic in the app is asynchronous in nature. [`react-native-onyx`](https://github.com/expensify/react-native-onyx) writes data async before updating subscribers.
88
- [Actions](https://github.com/Expensify/App#actions) do not typically return a `Promise` and therefore can't always be "awaited" before running an assertion.
99
- To test a result after some asynchronous code has run we can use [`Onyx.connect()`](https://github.com/Expensify/react-native-onyx/blob/2c94a94e51fab20330f7bd5381b72ea6c25553d9/lib/Onyx.js#L217-L231) and the helper method [`waitForBatchedUpdates()`](https://github.com/Expensify/ReactNativeChat/blob/ca2fa88a5789b82463d35eddc3d57f70a7286868/tests/utils/waitForBatchedUpdates.js#L1-L9) which returns a `Promise` and will ensure that all other `Promises` have finished running before resolving.
10-
- **Important Note:** When writing any asynchronous Jest test it's very important that your test itself **return a `Promise`**.
10+
- **Important Note:** When writing any asynchronous Jest test it's very important that your test itself **return a `Promise`**. In hooks like BeforeEach, BeforeAll, AfterAll, etc., you also need to return a promise or use async/await if they perform any asynchronous calls.
1111

1212
## Mocking Network Requests
1313

tests/ui/UnreadIndicatorsTest.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,12 @@ describe('Unread Indicators', () => {
187187

188188
beforeEach(() => {
189189
jest.clearAllMocks();
190-
Onyx.clear();
191190

191+
global.fetch = TestHelper.getGlobalFetchMock();
192192
// Unsubscribe to pusher channels
193193
PusherHelper.teardown();
194+
195+
return Onyx.clear().then(waitForBatchedUpdates);
194196
});
195197

196198
it('Display bold in the LHN for unread chat and new line indicator above the chat message when we navigate to it', () =>

0 commit comments

Comments
 (0)