Skip to content

Commit daba536

Browse files
fix(test): error logs in test runs
1 parent 1057445 commit daba536

File tree

8 files changed

+93
-41
lines changed

8 files changed

+93
-41
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,10 @@ describe('Gallery', () => {
265265
});
266266

267267
const component = await getComponent([image1]);
268-
const { getByA11yLabel, getByAccessibilityHint } = render(component);
268+
const { getByA11yLabel, getByAccessibilityHint, queryAllByTestId } = render(component);
269+
await waitFor(() => {
270+
expect(queryAllByTestId('gallery-container').length).toBe(1);
271+
});
269272

270273
fireEvent(getByA11yLabel('Gallery Image'), 'error');
271274
expect(getByAccessibilityHint('image-loading-error')).toBeTruthy();
@@ -278,7 +281,11 @@ describe('Gallery', () => {
278281
});
279282

280283
const component = await getComponent([image1]);
281-
const { getByA11yLabel, getByAccessibilityHint } = render(component);
284+
const { getByA11yLabel, getByAccessibilityHint, queryAllByTestId } = render(component);
285+
286+
await waitFor(() => {
287+
expect(queryAllByTestId('gallery-container').length).toBe(1);
288+
});
282289

283290
fireEvent(getByA11yLabel('Gallery Image'), 'onLoadStart');
284291
expect(getByAccessibilityHint('image-loading')).toBeTruthy();

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,8 @@ describe('Giphy', () => {
274274
});
275275
});
276276

277-
it('should render a error indicator in giphy image', () => {
278-
const { getByA11yLabel, getByAccessibilityHint } = render(
277+
it('should render a error indicator in giphy image', async () => {
278+
const { getByA11yLabel, getByAccessibilityHint, queryByTestId } = render(
279279
<OverlayProvider>
280280
<Chat client={chatClient}>
281281
<Channel channel={channel}>
@@ -284,12 +284,15 @@ describe('Giphy', () => {
284284
</Chat>
285285
</OverlayProvider>,
286286
);
287+
await waitFor(() => {
288+
expect(queryByTestId('giphy-attachment')).toBeTruthy();
289+
});
287290

288291
fireEvent(getByA11yLabel('Giphy Attachment Image'), 'error');
289292
expect(getByAccessibilityHint('image-loading-error')).toBeTruthy();
290293
});
291294

292-
it('should render a loading indicator in giphy image and when successful render the image', () => {
295+
it('should render a loading indicator in giphy image and when successful render the image', async () => {
293296
const { getByA11yLabel, getByAccessibilityHint } = render(
294297
<OverlayProvider>
295298
<Chat client={chatClient}>
@@ -299,8 +302,9 @@ describe('Giphy', () => {
299302
</Chat>
300303
</OverlayProvider>,
301304
);
302-
303-
expect(getByAccessibilityHint('image-loading')).toBeTruthy();
305+
await waitFor(() => {
306+
expect(getByAccessibilityHint('image-loading')).toBeTruthy();
307+
});
304308

305309
fireEvent(getByA11yLabel('Giphy Attachment Image'), 'onLoadStart');
306310

package/src/components/Chat/hooks/__tests__/useAppSettings.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ describe('useAppSettings', () => {
2121
userID: 'some-user-id',
2222
} as unknown as StreamChat,
2323
isOnline,
24+
false,
2425
);
2526

2627
return <Text>{JSON.stringify(appSettings)}</Text>;

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

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { SharedValue } from 'react-native-reanimated';
44

55
import { act } from 'react-test-renderer';
66

7-
import { fireEvent, render } from '@testing-library/react-native';
7+
import { fireEvent, render, waitFor } from '@testing-library/react-native';
88

99
import {
1010
ImageGalleryContext,
@@ -45,7 +45,7 @@ const getComponent = (props: Partial<ImageGalleryContextValue>) => (
4545
);
4646

4747
describe('ImageGallery', () => {
48-
it('render image gallery component', () => {
48+
it('render image gallery component', async () => {
4949
const { queryAllByA11yLabel } = render(
5050
getComponent({
5151
messages: [
@@ -59,11 +59,14 @@ describe('ImageGallery', () => {
5959
] as unknown as MessageType<DefaultStreamChatGenerics>[],
6060
}),
6161
);
62-
expect(queryAllByA11yLabel('Image Item')).toHaveLength(2);
63-
expect(queryAllByA11yLabel('Image Gallery Video')).toHaveLength(1);
62+
63+
await waitFor(() => {
64+
expect(queryAllByA11yLabel('Image Item')).toHaveLength(2);
65+
expect(queryAllByA11yLabel('Image Gallery Video')).toHaveLength(1);
66+
});
6467
});
6568

66-
it('handle handleLoad function when video item present and payload duration is available', () => {
69+
it('handle handleLoad function when video item present and payload duration is available', async () => {
6770
const attachment = generateVideoAttachment({ type: 'video' });
6871
const message = generateMessage({
6972
attachments: [attachment],
@@ -86,10 +89,13 @@ describe('ImageGallery', () => {
8689
});
8790

8891
const videoDurationComponent = getByA11yLabel('Video Duration');
89-
expect(videoDurationComponent.children[0]).toBe('00:10');
92+
93+
await waitFor(() => {
94+
expect(videoDurationComponent.children[0]).toBe('00:10');
95+
});
9096
});
9197

92-
it('handle handleLoad function when video item present and payload duration is undefined', () => {
98+
it('handle handleLoad function when video item present and payload duration is undefined', async () => {
9399
const { getByA11yLabel } = render(
94100
getComponent({
95101
messages: [
@@ -109,10 +115,12 @@ describe('ImageGallery', () => {
109115
});
110116

111117
const videoDurationComponent = getByA11yLabel('Video Duration');
112-
expect(videoDurationComponent.children[0]).toBe('00:00');
118+
await waitFor(() => {
119+
expect(videoDurationComponent.children[0]).toBe('00:00');
120+
});
113121
});
114122

115-
it('handle handleProgress function when video item present and payload is well defined', () => {
123+
it('handle handleProgress function when video item present and payload is well defined', async () => {
116124
const attachment = generateVideoAttachment({ type: 'video' });
117125
const message = generateMessage({
118126
attachments: [attachment],
@@ -143,10 +151,12 @@ describe('ImageGallery', () => {
143151

144152
const progressDurationComponent = getByA11yLabel('Progress Duration');
145153

146-
expect(progressDurationComponent.children[0]).toBe('00:03');
154+
await waitFor(() => {
155+
expect(progressDurationComponent.children[0]).toBe('00:03');
156+
});
147157
});
148158

149-
it('handle handleProgress function when video item present and payload is not defined', () => {
159+
it('handle handleProgress function when video item present and payload is not defined', async () => {
150160
const { getByA11yLabel } = render(
151161
getComponent({
152162
messages: [
@@ -171,10 +181,12 @@ describe('ImageGallery', () => {
171181

172182
const progressDurationComponent = getByA11yLabel('Progress Duration');
173183

174-
expect(progressDurationComponent.children[0]).toBe('00:00');
184+
await waitFor(() => {
185+
expect(progressDurationComponent.children[0]).toBe('00:00');
186+
});
175187
});
176188

177-
it('handle handleEnd function when video item present', () => {
189+
it('handle handleEnd function when video item present', async () => {
178190
const attachment = generateVideoAttachment({ type: 'video' });
179191
const message = generateMessage({
180192
attachments: [attachment],
@@ -198,7 +210,9 @@ describe('ImageGallery', () => {
198210
});
199211

200212
const progressDurationComponent = getByA11yLabel('Progress Duration');
201-
expect(getByA11yLabel('Play Icon')).not.toBeUndefined();
202-
expect(progressDurationComponent.children[0]).toBe('00:10');
213+
await waitFor(() => {
214+
expect(getByA11yLabel('Play Icon')).not.toBeUndefined();
215+
expect(progressDurationComponent.children[0]).toBe('00:10');
216+
});
203217
});
204218
});

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,13 @@ describe('ImageGalleryFooter', () => {
9797
</ImageGalleryContext.Provider>
9898
</OverlayProvider>,
9999
);
100-
expect(queryAllByText('Left element')).toHaveLength(1);
101-
expect(queryAllByText('Right element')).toHaveLength(1);
102-
expect(queryAllByText('Center element')).toHaveLength(1);
103-
expect(queryAllByText('Video Control element')).toHaveLength(1);
100+
101+
await waitFor(() => {
102+
expect(queryAllByText('Left element')).toHaveLength(1);
103+
expect(queryAllByText('Right element')).toHaveLength(1);
104+
expect(queryAllByText('Center element')).toHaveLength(1);
105+
expect(queryAllByText('Video Control element')).toHaveLength(1);
106+
});
104107
});
105108

106109
it('render image gallery footer component with custom component footer Grid Icon and Share Icon component', async () => {
@@ -147,8 +150,11 @@ describe('ImageGalleryFooter', () => {
147150
</ImageGalleryContext.Provider>
148151
</OverlayProvider>,
149152
);
150-
expect(queryAllByText('Share Icon element')).toHaveLength(1);
151-
expect(queryAllByText('Grid Icon element')).toHaveLength(1);
153+
154+
await waitFor(() => {
155+
expect(queryAllByText('Share Icon element')).toHaveLength(1);
156+
expect(queryAllByText('Grid Icon element')).toHaveLength(1);
157+
});
152158
});
153159

154160
it('should trigger the share button onPress Handler', async () => {

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,12 @@ describe('ImageGalleryHeader', () => {
9090
</ImageGalleryContext.Provider>
9191
</OverlayProvider>,
9292
);
93-
expect(queryAllByText('Left element')).toHaveLength(1);
94-
expect(queryAllByText('Right element')).toHaveLength(1);
95-
expect(queryAllByText('Center element')).toHaveLength(1);
93+
94+
await waitFor(() => {
95+
expect(queryAllByText('Left element')).toHaveLength(1);
96+
expect(queryAllByText('Right element')).toHaveLength(1);
97+
expect(queryAllByText('Center element')).toHaveLength(1);
98+
});
9699
});
97100

98101
it('render image gallery header component with custom Close Icon component', async () => {
@@ -132,7 +135,9 @@ describe('ImageGalleryHeader', () => {
132135
</ImageGalleryContext.Provider>
133136
</OverlayProvider>,
134137
);
135-
expect(queryAllByText('Close Icon element')).toHaveLength(1);
138+
await waitFor(() => {
139+
expect(queryAllByText('Close Icon element')).toHaveLength(1);
140+
});
136141
});
137142

138143
it('should trigger the hideOverlay function on button onPress', async () => {

package/src/contexts/messageInputContext/__tests__/MessageInputContext.test.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { TextInput } from 'react-native';
44

55
import { act, renderHook } from '@testing-library/react-hooks';
66

7+
import { waitFor } from '@testing-library/react-native';
78
import type { AppSettingsAPIResponse, StreamChat } from 'stream-chat';
89

910
import { ChatContextValue, ChatProvider } from '../../../contexts/chatContext/ChatContext';
@@ -167,7 +168,7 @@ describe('MessageInputContext', () => {
167168
expect(result.current.text).toBe('/');
168169
});
169170

170-
it('openMentionPicker works', () => {
171+
it('openMentionPicker works', async () => {
171172
const { result } = renderHook(() => useMessageInputContext(), {
172173
initialProps: {
173174
editing: true,
@@ -180,7 +181,9 @@ describe('MessageInputContext', () => {
180181
result.current.openMentionsPicker();
181182
});
182183

183-
expect(result.current.text).toBe('@');
184+
await waitFor(() => {
185+
expect(result.current.text).toBe('@');
186+
});
184187
});
185188

186189
it('openAttachmentPicker works', async () => {
@@ -203,6 +206,8 @@ describe('MessageInputContext', () => {
203206
result.current.openAttachmentPicker();
204207
});
205208

206-
expect(await result.current.pickFile()).toBe(undefined);
209+
await waitFor(async () => {
210+
expect(await result.current.pickFile()).toBe(undefined);
211+
});
207212
});
208213
});

package/src/contexts/messageInputContext/__tests__/uploadFile.test.tsx

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { act } from 'react-test-renderer';
33

44
import { renderHook } from '@testing-library/react-hooks';
55

6+
import { waitFor } from '@testing-library/react-native';
7+
68
import { generateFileUploadPreview } from '../../../mock-builders/generator/attachment';
79
import type { DefaultStreamChatGenerics } from '../../../types/types';
810
import {
@@ -31,7 +33,7 @@ const Wrapper = <StreamChatGenerics extends DefaultStreamChatGenerics = DefaultS
3133
);
3234

3335
describe("MessageInputContext's uploadFile", () => {
34-
it('uploadFile works', () => {
36+
it('uploadFile works', async () => {
3537
const doDocUploadRequestMock = jest.fn().mockResolvedValue({
3638
file: {
3739
url: '',
@@ -46,16 +48,20 @@ describe("MessageInputContext's uploadFile", () => {
4648
wrapper: Wrapper,
4749
});
4850

49-
expect(result.current.fileUploads).toHaveLength(0);
51+
await waitFor(() => {
52+
expect(result.current.fileUploads).toHaveLength(0);
53+
});
5054

5155
act(() => {
5256
result.current.uploadFile({ newFile: generateFileUploadPreview({ state: '' }) });
5357
});
5458

55-
expect(doDocUploadRequestMock).toHaveBeenCalled();
59+
await waitFor(() => {
60+
expect(doDocUploadRequestMock).toHaveBeenCalled();
61+
});
5662
});
5763

58-
it('uploadFile catch block gets executed', () => {
64+
it('uploadFile catch block gets executed', async () => {
5965
const doDocUploadRequestMock = jest.fn().mockResolvedValue(new Error('This is an error'));
6066
const { result } = renderHook(() => useMessageInputContext(), {
6167
initialProps: {
@@ -65,12 +71,16 @@ describe("MessageInputContext's uploadFile", () => {
6571
wrapper: Wrapper,
6672
});
6773

68-
expect(result.current.fileUploads).toHaveLength(0);
74+
await waitFor(() => {
75+
expect(result.current.fileUploads).toHaveLength(0);
76+
});
6977

7078
act(() => {
7179
result.current.uploadFile({ newFile: generateFileUploadPreview({ state: '' }) });
7280
});
7381

74-
expect(result.current.fileUploads.length).toBe(0);
82+
await waitFor(() => {
83+
expect(result.current.fileUploads.length).toBe(0);
84+
});
7585
});
7686
});

0 commit comments

Comments
 (0)