Skip to content

Commit 1162171

Browse files
committed
fix: update unit tests for React 19 compatibility
1 parent 0840c0b commit 1162171

2 files changed

Lines changed: 29 additions & 35 deletions

File tree

app/components/UI/Rewards/hooks/useCampaignParticipantOutcome.test.ts

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { renderHook, act } from '@testing-library/react-hooks';
1+
import { renderHook, act, waitFor } from '@testing-library/react-native';
22
import { useSelector } from 'react-redux';
33
import Engine from '../../../../core/Engine';
44
import { selectRewardsSubscriptionId } from '../../../../selectors/rewards';
@@ -69,62 +69,58 @@ describe('useCampaignParticipantOutcome', () => {
6969
setupSelectors();
7070
mockCall.mockResolvedValue(MOCK_OUTCOME);
7171

72-
const { result, waitForNextUpdate } = renderHook(() =>
72+
const { result } = renderHook(() =>
7373
useCampaignParticipantOutcome(CAMPAIGN_ID, CONFIG),
7474
);
7575

76-
await act(async () => {
77-
await waitForNextUpdate();
76+
await waitFor(() => {
77+
expect(result.current.isLoading).toBe(false);
78+
expect(result.current.outcome).toEqual(MOCK_OUTCOME);
7879
});
7980

8081
expect(mockCall).toHaveBeenCalledWith(
8182
MESSENGER_ACTION,
8283
CAMPAIGN_ID,
8384
SUBSCRIPTION_ID,
8485
);
85-
expect(result.current.outcome).toEqual(MOCK_OUTCOME);
86-
expect(result.current.isLoading).toBe(false);
8786
expect(result.current.hasError).toBe(false);
8887
});
8988

9089
it('returns null outcome when campaignId is undefined', async () => {
9190
setupSelectors();
92-
const { result, waitForNextUpdate } = renderHook(() =>
91+
const { result } = renderHook(() =>
9392
useCampaignParticipantOutcome(undefined, CONFIG),
9493
);
95-
await act(async () => {
96-
await waitForNextUpdate().catch(() => undefined);
94+
await waitFor(() => {
95+
expect(result.current.isLoading).toBe(false);
9796
});
9897
expect(result.current.outcome).toBeNull();
99-
expect(result.current.isLoading).toBe(false);
10098
expect(result.current.hasError).toBe(false);
10199
expect(mockCall).not.toHaveBeenCalled();
102100
});
103101

104102
it('returns null outcome when subscriptionId is missing', async () => {
105103
setupSelectors({ subscriptionId: null });
106-
const { result, waitForNextUpdate } = renderHook(() =>
104+
const { result } = renderHook(() =>
107105
useCampaignParticipantOutcome(CAMPAIGN_ID, CONFIG),
108106
);
109-
await act(async () => {
110-
await waitForNextUpdate().catch(() => undefined);
107+
await waitFor(() => {
108+
expect(result.current.isLoading).toBe(false);
111109
});
112110
expect(result.current.outcome).toBeNull();
113-
expect(result.current.isLoading).toBe(false);
114111
expect(result.current.hasError).toBe(false);
115112
expect(mockCall).not.toHaveBeenCalled();
116113
});
117114

118115
it('returns null outcome when user is not opted in', async () => {
119116
setupSelectors({ isOptedIn: false });
120-
const { result, waitForNextUpdate } = renderHook(() =>
117+
const { result } = renderHook(() =>
121118
useCampaignParticipantOutcome(CAMPAIGN_ID, CONFIG),
122119
);
123-
await act(async () => {
124-
await waitForNextUpdate().catch(() => undefined);
120+
await waitFor(() => {
121+
expect(result.current.isLoading).toBe(false);
125122
});
126123
expect(result.current.outcome).toBeNull();
127-
expect(result.current.isLoading).toBe(false);
128124
expect(result.current.hasError).toBe(false);
129125
expect(mockCall).not.toHaveBeenCalled();
130126
});
@@ -133,41 +129,39 @@ describe('useCampaignParticipantOutcome', () => {
133129
setupSelectors();
134130
mockCall.mockRejectedValue(new Error('fetch failed'));
135131

136-
const { result, waitForNextUpdate } = renderHook(() =>
132+
const { result } = renderHook(() =>
137133
useCampaignParticipantOutcome(CAMPAIGN_ID, CONFIG),
138134
);
139135

140-
await act(async () => {
141-
await waitForNextUpdate();
136+
await waitFor(() => {
137+
expect(result.current.isLoading).toBe(false);
138+
expect(result.current.hasError).toBe(true);
142139
});
143140

144141
expect(result.current.outcome).toBeNull();
145-
expect(result.current.isLoading).toBe(false);
146-
expect(result.current.hasError).toBe(true);
147142
});
148143

149144
it('resets state when campaignId changes to undefined', async () => {
150145
setupSelectors();
151146
mockCall.mockResolvedValue(MOCK_OUTCOME);
152147

153-
const initialProps: { id: string | undefined } = { id: CAMPAIGN_ID };
154-
const { result, waitForNextUpdate, rerender } = renderHook(
148+
const { result, rerender } = renderHook(
155149
({ id }: { id: string | undefined }) =>
156150
useCampaignParticipantOutcome(id, CONFIG),
157-
{ initialProps },
151+
{ initialProps: { id: CAMPAIGN_ID } },
158152
);
159153

160-
await act(async () => {
161-
await waitForNextUpdate();
154+
await waitFor(() => {
155+
expect(result.current.isLoading).toBe(false);
156+
expect(result.current.outcome).toEqual(MOCK_OUTCOME);
162157
});
163-
expect(result.current.outcome).toEqual(MOCK_OUTCOME);
164158

165159
rerender({ id: undefined });
166-
await act(async () => {
167-
await waitForNextUpdate().catch(() => undefined);
160+
161+
await waitFor(() => {
162+
expect(result.current.outcome).toBeNull();
163+
expect(result.current.isLoading).toBe(false);
164+
expect(result.current.hasError).toBe(false);
168165
});
169-
expect(result.current.outcome).toBeNull();
170-
expect(result.current.isLoading).toBe(false);
171-
expect(result.current.hasError).toBe(false);
172166
});
173167
});

app/components/Views/SimpleWebview/index.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ describe('SimpleWebview', () => {
5050
expect.objectContaining({ onPress: expect.any(Function) }),
5151
]),
5252
}),
53-
expect.anything(),
53+
undefined,
5454
);
5555
});
5656

0 commit comments

Comments
 (0)