Skip to content

Commit 46d2605

Browse files
committed
fix: tests
1 parent 4042ec1 commit 46d2605

22 files changed

+134
-139
lines changed

package/src/components/Attachment/__tests__/Giphy.test.js

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22

33
import {
4+
act,
45
cleanup,
56
fireEvent,
67
render,
@@ -177,11 +178,15 @@ describe('Giphy', () => {
177178

178179
await waitFor(() => screen.getByTestId(`${attachment.actions[2].value}-action-button`));
179180

180-
expect(screen.getByTestId('giphy-action-attachment')).toContainElement(
181-
screen.getByTestId(`${attachment.actions[2].value}-action-button`),
182-
);
181+
await waitFor(() => {
182+
expect(screen.getByTestId('giphy-action-attachment')).toContainElement(
183+
screen.getByTestId(`${attachment.actions[2].value}-action-button`),
184+
);
185+
});
183186

184-
user.press(screen.getByTestId(`${attachment.actions[2].value}-action-button`));
187+
act(() => {
188+
user.press(screen.getByTestId(`${attachment.actions[2].value}-action-button`));
189+
});
185190

186191
await waitFor(() => {
187192
expect(handleAction).toHaveBeenCalledTimes(1);
@@ -202,11 +207,15 @@ describe('Giphy', () => {
202207

203208
await waitFor(() => screen.getByTestId(`${attachment.actions[1].value}-action-button`));
204209

205-
expect(screen.getByTestId('giphy-action-attachment')).toContainElement(
206-
screen.getByTestId(`${attachment.actions[1].value}-action-button`),
207-
);
210+
await waitFor(() => {
211+
expect(screen.getByTestId('giphy-action-attachment')).toContainElement(
212+
screen.getByTestId(`${attachment.actions[1].value}-action-button`),
213+
);
214+
});
208215

209-
user.press(screen.getByTestId(`${attachment.actions[1].value}-action-button`));
216+
act(() => {
217+
user.press(screen.getByTestId(`${attachment.actions[1].value}-action-button`));
218+
});
210219

211220
await waitFor(() => {
212221
expect(handleAction).toHaveBeenCalledTimes(1);
@@ -227,11 +236,15 @@ describe('Giphy', () => {
227236

228237
await waitFor(() => screen.getByTestId(`${attachment.actions[0].value}-action-button`));
229238

230-
expect(screen.getByTestId('giphy-action-attachment')).toContainElement(
231-
screen.getByTestId(`${attachment.actions[0].value}-action-button`),
232-
);
239+
await waitFor(() => {
240+
expect(screen.getByTestId('giphy-action-attachment')).toContainElement(
241+
screen.getByTestId(`${attachment.actions[0].value}-action-button`),
242+
);
243+
});
233244

234-
user.press(screen.getByTestId(`${attachment.actions[0].value}-action-button`));
245+
act(() => {
246+
user.press(screen.getByTestId(`${attachment.actions[0].value}-action-button`));
247+
});
235248

236249
await waitFor(() => {
237250
expect(handleAction).toHaveBeenCalledTimes(1);
@@ -303,8 +316,13 @@ describe('Giphy', () => {
303316
expect(screen.queryByTestId('giphy-attachment')).toBeTruthy();
304317
});
305318

306-
fireEvent(screen.getByLabelText('Giphy Attachment Image'), 'error');
307-
expect(screen.getByAccessibilityHint('image-loading-error')).toBeTruthy();
319+
act(() => {
320+
fireEvent(screen.getByLabelText('Giphy Attachment Image'), 'error');
321+
});
322+
323+
await waitFor(() => {
324+
expect(screen.getByAccessibilityHint('image-loading-error')).toBeTruthy();
325+
});
308326
});
309327

310328
it('should render a loading indicator in giphy image and when successful render the image', async () => {
@@ -321,13 +339,22 @@ describe('Giphy', () => {
321339
expect(screen.getByAccessibilityHint('image-loading')).toBeTruthy();
322340
});
323341

324-
fireEvent(screen.getByLabelText('Giphy Attachment Image'), 'onLoadStart');
342+
act(() => {
343+
fireEvent(screen.getByLabelText('Giphy Attachment Image'), 'onLoadStart');
344+
});
325345

326-
expect(screen.getByAccessibilityHint('image-loading')).toBeTruthy();
346+
await waitFor(() => {
347+
expect(screen.getByAccessibilityHint('image-loading')).toBeTruthy();
348+
});
327349

328-
fireEvent(screen.getByLabelText('Giphy Attachment Image'), 'onLoadFinish');
350+
act(() => {
351+
fireEvent(screen.getByLabelText('Giphy Attachment Image'), 'onLoad');
352+
});
329353

330354
waitForElementToBeRemoved(() => screen.getByAccessibilityHint('image-loading'));
331-
expect(screen.getByLabelText('Giphy Attachment Image')).toBeTruthy();
355+
356+
await waitFor(() => {
357+
expect(screen.getByLabelText('Giphy Attachment Image')).toBeTruthy();
358+
});
332359
});
333360
});

package/src/components/AutoCompleteInput/__tests__/AutoCompleteInput.test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ describe('AutoCompleteInput', () => {
9393
});
9494
});
9595

96-
it('should call the textComposer handleChange when the onChangeText is triggered', () => {
96+
it('should call the textComposer handleChange when the onChangeText is triggered', async () => {
9797
const { textComposer } = channel.messageComposer;
9898

9999
const spyHandleChange = jest.spyOn(textComposer, 'handleChange');
@@ -111,7 +111,7 @@ describe('AutoCompleteInput', () => {
111111
userEvent.type(input, 'hello');
112112
});
113113

114-
waitFor(() => {
114+
await waitFor(() => {
115115
expect(spyHandleChange).toHaveBeenCalled();
116116
expect(spyHandleChange).toHaveBeenCalledWith({
117117
selection: { end: 5, start: 5 },
@@ -121,7 +121,7 @@ describe('AutoCompleteInput', () => {
121121
});
122122
});
123123

124-
it('should style the text input with maxHeight that is set by the layout', () => {
124+
it('should style the text input with maxHeight that is set by the layout', async () => {
125125
const channelProps = { channel };
126126
const props = { numberOfLines: 10 };
127127

@@ -139,12 +139,12 @@ describe('AutoCompleteInput', () => {
139139
});
140140
});
141141

142-
waitFor(() => {
142+
await waitFor(() => {
143143
expect(input.props.style[1].maxHeight).toBe(1000);
144144
});
145145
});
146146

147-
it('should call the textComposer setSelection when the onSelectionChange is triggered', () => {
147+
it('should call the textComposer setSelection when the onSelectionChange is triggered', async () => {
148148
const { textComposer } = channel.messageComposer;
149149

150150
const spySetSelection = jest.spyOn(textComposer, 'setSelection');
@@ -166,7 +166,7 @@ describe('AutoCompleteInput', () => {
166166
});
167167
});
168168

169-
waitFor(() => {
169+
await waitFor(() => {
170170
expect(spySetSelection).toHaveBeenCalled();
171171
expect(spySetSelection).toHaveBeenCalledWith({ end: 5, start: 5 });
172172
});

package/src/components/ChannelList/hooks/listeners/__tests__/useChannelUpdated.test.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import React, { useState } from 'react';
22
import { Image, Text } from 'react-native';
33

4-
import { act } from 'react-test-renderer';
5-
6-
import { render, waitFor } from '@testing-library/react-native';
4+
import { act, render, waitFor } from '@testing-library/react-native';
75
import type { Channel, ChannelResponse, Event, StreamChat } from 'stream-chat';
86

97
import { ChatContext, useChannelUpdated } from '../../../../../index';

package/src/components/ImageGallery/__tests__/AnimatedVideoGallery.test.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ import React from 'react';
22

33
import type { SharedValue } from 'react-native-reanimated';
44

5-
import { act } from 'react-test-renderer';
6-
7-
import { fireEvent, render, screen } from '@testing-library/react-native';
5+
import { act, fireEvent, render, screen } from '@testing-library/react-native';
86

97
import { ThemeProvider } from '../../../contexts/themeContext/ThemeContext';
108
import { defaultTheme } from '../../../contexts/themeContext/utils/theme';

package/src/components/ImageGallery/__tests__/ImageGalleryFooter.test.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import React from 'react';
33
import { Text, View } from 'react-native';
44
import type { SharedValue } from 'react-native-reanimated';
55

6-
import { ReactTestInstance } from 'react-test-renderer';
7-
86
import { render, screen, userEvent, waitFor } from '@testing-library/react-native';
97

108
import { LocalMessage } from 'stream-chat';
@@ -188,8 +186,10 @@ describe('ImageGalleryFooter', () => {
188186
</OverlayProvider>,
189187
);
190188

189+
const { getByLabelText } = screen;
190+
191191
await waitFor(() => {
192-
user.press(screen.queryByLabelText('Share Button') as ReactTestInstance);
192+
user.press(getByLabelText('Share Button'));
193193
});
194194

195195
await waitFor(() => {
@@ -231,8 +231,10 @@ describe('ImageGalleryFooter', () => {
231231
</OverlayProvider>,
232232
);
233233

234+
const { getByLabelText } = screen;
235+
234236
await waitFor(() => {
235-
user.press(screen.queryByLabelText('Share Button') as ReactTestInstance);
237+
user.press(getByLabelText('Share Button'));
236238
});
237239

238240
await waitFor(() => {
@@ -280,8 +282,10 @@ describe('ImageGalleryFooter', () => {
280282
</OverlayProvider>,
281283
);
282284

285+
const { getByLabelText } = screen;
286+
283287
await waitFor(() => {
284-
user.press(screen.queryByLabelText('Share Button') as ReactTestInstance);
288+
user.press(getByLabelText('Share Button'));
285289
});
286290

287291
await waitFor(() => {

package/src/components/ImageGallery/__tests__/ImageGalleryGrid.test.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import React from 'react';
22

33
import { Text, View } from 'react-native';
4-
import { act } from 'react-test-renderer';
54

6-
import { fireEvent, render, screen } from '@testing-library/react-native';
5+
import { act, fireEvent, render, screen } from '@testing-library/react-native';
76

87
import { ThemeProvider } from '../../../contexts/themeContext/ThemeContext';
98
import { defaultTheme } from '../../../contexts/themeContext/utils/theme';

package/src/components/ImageGallery/__tests__/ImageGalleryHeader.test.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ import React from 'react';
33
import { Text, View } from 'react-native';
44
import type { SharedValue } from 'react-native-reanimated';
55

6-
import { act } from 'react-test-renderer';
7-
8-
import { render, screen, userEvent, waitFor } from '@testing-library/react-native';
6+
import { act, render, screen, userEvent, waitFor } from '@testing-library/react-native';
97

108
import { LocalMessage } from 'stream-chat';
119

package/src/components/ImageGallery/__tests__/ImageGalleryOverlay.test.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ import React from 'react';
33
import { State } from 'react-native-gesture-handler';
44
import type { SharedValue } from 'react-native-reanimated';
55

6-
import { act } from 'react-test-renderer';
7-
8-
import { fireEvent, render, waitFor } from '@testing-library/react-native';
6+
import { act, fireEvent, render, waitFor } from '@testing-library/react-native';
97

108
import { LocalMessage } from 'stream-chat';
119

package/src/components/ImageGallery/__tests__/ImageGalleryVideoControl.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React from 'react';
22

3-
import { act, ReactTestInstance } from 'react-test-renderer';
3+
import { ReactTestInstance } from 'react-test-renderer';
44

5-
import { render, screen, userEvent, waitFor } from '@testing-library/react-native';
5+
import { act, render, screen, userEvent, waitFor } from '@testing-library/react-native';
66

77
import dayjs from 'dayjs';
88
import duration from 'dayjs/plugin/duration';

package/src/components/Message/MessageSimple/__tests__/MessageTextContainer.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ import { Chat } from '../../../Chat/Chat';
2222
import { MessageList } from '../../../MessageList/MessageList';
2323
import { MessageTextContainer } from '../MessageTextContainer';
2424

25-
afterEach(cleanup);
26-
2725
describe('MessageTextContainer', () => {
26+
afterEach(cleanup);
27+
2828
it('should render message text container', async () => {
2929
const staticUser = generateStaticUser(1);
3030
const message = generateMessage({

0 commit comments

Comments
 (0)