Skip to content

Commit d06b68b

Browse files
authored
Merge pull request Expensify#63823 from software-mansion-labs/war-in/update-testing-library
[No QA] [Pre RN 0.79] Bump `@testing-library/react-native`
2 parents c66008f + e27dfb7 commit d06b68b

9 files changed

Lines changed: 112 additions & 38 deletions

jest/setupAfterEnv.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import '@testing-library/react-native/extend-expect';
1+
import '@testing-library/react-native';
22

33
jest.useRealTimers();

package-lock.json

Lines changed: 88 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@
254254
"@storybook/react-webpack5": "^8.6.9",
255255
"@storybook/theming": "^8.6.9",
256256
"@svgr/webpack": "^6.0.0",
257-
"@testing-library/react-native": "12.8.1",
257+
"@testing-library/react-native": "13.2.0",
258258
"@trivago/prettier-plugin-sort-imports": "^4.2.0",
259259
"@types/base-64": "^1.0.2",
260260
"@types/canvas-size": "^1.2.2",

tests/perf-test/SidebarLinks.perf-test.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,11 @@ describe('SidebarLinks', () => {
9494

9595
test('[SidebarLinks] should click on list item', async () => {
9696
const scenario = async () => {
97-
await wrapInAct(async () => {
97+
await waitFor(async () => {
9898
const button = await screen.findByTestId('1');
99-
fireEvent.press(button);
99+
await wrapInAct(() => {
100+
fireEvent.press(button);
101+
});
100102
});
101103
};
102104

tests/ui/GroupChatNameTests.tsx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,8 @@ function signInAndGetApp(reportName = '', participantAccountIDs?: number[]): Pro
8383
const hintText = translateLocal('loginForm.loginForm');
8484
const loginForm = screen.queryAllByLabelText(hintText);
8585
expect(loginForm).toHaveLength(1);
86-
87-
await act(async () => {
88-
await TestHelper.signInWithTestUser(USER_A_ACCOUNT_ID, USER_A_EMAIL, undefined, undefined, 'A');
89-
});
90-
return waitForBatchedUpdatesWithAct();
9186
})
87+
.then(async () => TestHelper.signInWithTestUser(USER_A_ACCOUNT_ID, USER_A_EMAIL, undefined, undefined, 'A'))
9288
.then(() => {
9389
subscribeToUserEvents();
9490
return waitForBatchedUpdates();
@@ -212,7 +208,7 @@ describe('Tests for group chat name', () => {
212208
})
213209
.then(waitForBatchedUpdates)
214210
.then(async () => {
215-
await act(() => transitionEndCB?.());
211+
act(() => transitionEndCB?.());
216212
const name = 'A, B, C, D';
217213
const displayNameTexts = screen.queryAllByLabelText(name);
218214
return waitFor(() => expect(displayNameTexts).toHaveLength(1));
@@ -248,7 +244,7 @@ describe('Tests for group chat name', () => {
248244
.then(() => navigateToSidebarOption(0))
249245
.then(waitForBatchedUpdates)
250246
.then(async () => {
251-
await act(() => transitionEndCB?.());
247+
act(() => transitionEndCB?.());
252248
const name = 'A, B, C, D, E...';
253249
const displayNameTexts = screen.queryAllByLabelText(name);
254250
return waitFor(() => expect(displayNameTexts).toHaveLength(1));
@@ -275,7 +271,7 @@ describe('Tests for group chat name', () => {
275271
})
276272
.then(waitForBatchedUpdates)
277273
.then(async () => {
278-
await act(() => transitionEndCB?.());
274+
act(() => transitionEndCB?.());
279275
const name = 'Test chat';
280276
const displayNameTexts = screen.queryAllByLabelText(name);
281277
return waitFor(() => expect(displayNameTexts).toHaveLength(1));
@@ -302,7 +298,7 @@ describe('Tests for group chat name', () => {
302298
})
303299
.then(waitForBatchedUpdates)
304300
.then(async () => {
305-
await act(() => transitionEndCB?.());
301+
act(() => transitionEndCB?.());
306302
const name = "Let's talk";
307303
const displayNameTexts = screen.queryAllByLabelText(name);
308304
return waitFor(() => expect(displayNameTexts).toHaveLength(1));

tests/ui/LHNItemsPresence.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ describe('SidebarLinksData', () => {
149149
expect(getOptionRows()).toHaveLength(0);
150150

151151
// When the SidebarLinks are rendered again with the current active report ID.
152-
LHNTestUtils.getDefaultRenderedSidebarLinks(report.reportID);
152+
await LHNTestUtils.getDefaultRenderedSidebarLinks(report.reportID);
153153

154154
await waitForBatchedUpdatesWithAct();
155155
// Then the active report should be displayed as part of LHN,

tests/ui/NewChatPageTest.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ describe('NewChatPage', () => {
4747
await Onyx.merge(ONYXKEYS.PERSONAL_DETAILS_LIST, fakePersonalDetails);
4848
render(<NewChatPage />, {wrapper});
4949
await waitForBatchedUpdatesWithAct();
50-
await act(() => {
50+
act(() => {
5151
(NativeNavigation as NativeNavigationMock).triggerTransitionEnd();
5252
});
5353
const spy = jest.spyOn(SectionList.prototype, 'scrollToLocation');
@@ -72,7 +72,7 @@ describe('NewChatPage', () => {
7272
// And NewChatPage is opened
7373
render(<NewChatPage />, {wrapper});
7474
await waitForBatchedUpdatesWithAct();
75-
await act(() => {
75+
act(() => {
7676
(NativeNavigation as NativeNavigationMock).triggerTransitionEnd();
7777
});
7878

tests/ui/PaginationTest.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable @typescript-eslint/naming-convention */
22
import * as NativeNavigation from '@react-navigation/native';
3-
import {act, fireEvent, render, screen, within} from '@testing-library/react-native';
3+
import {act, fireEvent, render, screen, waitFor, within} from '@testing-library/react-native';
44
import {addSeconds, format, subMinutes} from 'date-fns';
55
import React from 'react';
66
import Onyx from 'react-native-onyx';
@@ -91,7 +91,7 @@ function getReportActions(reportID?: string) {
9191
async function navigateToSidebarOption(reportID: string): Promise<void> {
9292
const optionRow = screen.getByTestId(reportID);
9393
fireEvent(optionRow, 'press');
94-
await act(() => {
94+
await waitFor(() => {
9595
(NativeNavigation as NativeNavigationMock).triggerTransitionEnd();
9696
});
9797
// ReportScreen relies on the onLayout event to receive updates from onyx.
@@ -335,7 +335,7 @@ describe('Pagination', () => {
335335

336336
const link = screen.getByText('Link 1');
337337
fireEvent(link, 'press');
338-
await act(() => {
338+
await waitFor(() => {
339339
(NativeNavigation as NativeNavigationMock).triggerTransitionEnd();
340340
});
341341
// Due to https://github.com/facebook/react-native/commit/3485e9ed871886b3e7408f90d623da5c018da493

tests/ui/UnreadIndicatorsTest.tsx

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,8 @@ function signInAndGetAppWithUnreadChat(): Promise<void> {
135135
const hintText = translateLocal('loginForm.loginForm');
136136
const loginForm = screen.queryAllByLabelText(hintText);
137137
expect(loginForm).toHaveLength(1);
138-
139-
await act(async () => {
140-
await TestHelper.signInWithTestUser(USER_A_ACCOUNT_ID, USER_A_EMAIL, undefined, undefined, 'A');
141-
});
142-
return waitForBatchedUpdatesWithAct();
143138
})
139+
.then(async () => TestHelper.signInWithTestUser(USER_A_ACCOUNT_ID, USER_A_EMAIL, undefined, undefined, 'A'))
144140
.then(() => {
145141
subscribeToUserEvents();
146142
return waitForBatchedUpdates();
@@ -220,7 +216,7 @@ describe('Unread Indicators', () => {
220216
return navigateToSidebarOption(0);
221217
})
222218
.then(async () => {
223-
await act(() => (NativeNavigation as NativeNavigationMock).triggerTransitionEnd());
219+
act(() => (NativeNavigation as NativeNavigationMock).triggerTransitionEnd());
224220

225221
// That the report actions are visible along with the created action
226222
const welcomeMessageHintText = translateLocal('accessibilityHints.chatWelcomeMessage');
@@ -244,8 +240,8 @@ describe('Unread Indicators', () => {
244240
signInAndGetAppWithUnreadChat()
245241
// Navigate to the unread chat from the sidebar
246242
.then(() => navigateToSidebarOption(0))
247-
.then(async () => {
248-
await act(() => (NativeNavigation as NativeNavigationMock).triggerTransitionEnd());
243+
.then(() => {
244+
act(() => (NativeNavigation as NativeNavigationMock).triggerTransitionEnd());
249245
// Verify the unread indicator is present
250246
const newMessageLineIndicatorHintText = translateLocal('accessibilityHints.newMessageLineIndicator');
251247
const unreadIndicator = screen.queryAllByLabelText(newMessageLineIndicatorHintText);
@@ -366,8 +362,8 @@ describe('Unread Indicators', () => {
366362
return navigateToSidebarOption(0);
367363
})
368364
.then(waitForBatchedUpdates)
369-
.then(async () => {
370-
await act(() => (NativeNavigation as NativeNavigationMock).triggerTransitionEnd());
365+
.then(() => {
366+
act(() => (NativeNavigation as NativeNavigationMock).triggerTransitionEnd());
371367
// Verify that report we navigated to appears in a "read" state while the original unread report still shows as unread
372368
const hintText = translateLocal('accessibilityHints.chatUserDisplayNames');
373369
const displayNameTexts = screen.queryAllByLabelText(hintText, {includeHiddenElements: true});
@@ -444,7 +440,7 @@ describe('Unread Indicators', () => {
444440
return navigateToSidebarOption(0);
445441
})
446442
.then(async () => {
447-
await act(() => (NativeNavigation as NativeNavigationMock).triggerTransitionEnd());
443+
act(() => (NativeNavigation as NativeNavigationMock).triggerTransitionEnd());
448444
const newMessageLineIndicatorHintText = translateLocal('accessibilityHints.newMessageLineIndicator');
449445
const unreadIndicator = screen.queryAllByLabelText(newMessageLineIndicatorHintText);
450446
expect(unreadIndicator).toHaveLength(1);

0 commit comments

Comments
 (0)