Skip to content

Commit 3af204b

Browse files
Fixing the tests and issue with react-test-renderer
1 parent 881beae commit 3af204b

File tree

5 files changed

+251
-215
lines changed

5 files changed

+251
-215
lines changed

jest-setup.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
import { registerNativeHandlers } from './src/native';
22

3+
// eslint-disable-next-line no-underscore-dangle
4+
const _consoleE = console.error;
5+
console.error = (e) => {
6+
// For some reason following error gets rased from waitFor function.
7+
// Source of the error is in react-test-renderer, although cause of the
8+
// issue is unknown. Until we figure out the proper way to fix this issue,
9+
// following hack should work. We just suppress this particular error.
10+
// It should be safe since the error is only raised in dev environment
11+
// https://github.com/facebook/react/blob/b683c07ccce340b9d687683d5dd7347a4c866787/packages/react-dom/src/test-utils/ReactTestUtilsAct.js#L121
12+
if (e.indexOf('You called act(async () => ...) without await') === -1) {
13+
_consoleE(e);
14+
}
15+
};
16+
317
registerNativeHandlers({
418
NetInfo: {
519
addEventListener: () => {},

src/components/Avatar/__tests__/Avatar.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react';
2-
import { getNodeText, render, waitFor } from '@testing-library/react-native';
2+
import { render, waitFor } from '@testing-library/react-native';
33

44
import Avatar from '../Avatar';
55

@@ -49,7 +49,7 @@ describe('Avatar', () => {
4949
await waitFor(() => {
5050
expect(queryByTestId('avatar-image')).toBeFalsy();
5151
expect(queryByTestId('avatar-text')).toBeTruthy();
52-
expect(getNodeText(getByTestId('avatar-text'))).toBe('TU');
52+
expect(getByTestId('avatar-text')).toHaveTextContent('TU');
5353
});
5454
});
5555

@@ -61,7 +61,7 @@ describe('Avatar', () => {
6161
await waitFor(() => {
6262
expect(queryByTestId('avatar-image')).toBeFalsy();
6363
expect(queryByTestId('avatar-text')).toBeTruthy();
64-
expect(getNodeText(getByTestId('avatar-text'))).toBe('TU');
64+
expect(getByTestId('avatar-text')).toHaveTextContent('TU');
6565
});
6666
});
6767
});

src/components/ChannelPreview/__tests__/ChannelPreview.test.js

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
import React from 'react';
2-
import {
3-
act,
4-
getNodeText,
5-
render,
6-
waitFor,
7-
} from '@testing-library/react-native';
2+
import { act, render, waitFor } from '@testing-library/react-native';
83

94
import {
105
dispatchMessageDeletedEvent,
@@ -87,13 +82,15 @@ describe('ChannelPreview', () => {
8782
const { getByTestId } = render(getComponent());
8883

8984
await waitFor(() => getByTestId('channel-id'));
90-
expect(getNodeText(getByTestId('unread-count'))).toBe('20');
91-
await act(async () => {
92-
await dispatchMessageReadEvent(chatClient, clientUser, channel);
85+
86+
expect(getByTestId('unread-count')).toHaveTextContent('20');
87+
88+
act(() => {
89+
dispatchMessageReadEvent(chatClient, clientUser, channel);
9390
});
9491

9592
await waitFor(() => {
96-
expect(getNodeText(getByTestId('unread-count'))).toBe('0');
93+
expect(getByTestId('unread-count')).toHaveTextContent('0');
9794
});
9895
});
9996

@@ -117,12 +114,12 @@ describe('ChannelPreview', () => {
117114
user: clientUser,
118115
});
119116

120-
await act(async () => {
121-
await dispatcher(chatClient, message, channel);
117+
act(() => {
118+
dispatcher(chatClient, message, channel);
122119
});
123120

124121
await waitFor(() => {
125-
expect(getNodeText(getByTestId('last-event-message'))).toBe(
122+
expect(getByTestId('last-event-message')).toHaveTextContent(
126123
message.text,
127124
);
128125
});
@@ -143,12 +140,12 @@ describe('ChannelPreview', () => {
143140

144141
channel.countUnread = () => 10;
145142

146-
await act(async () => {
147-
await dispatchMessageNewEvent(chatClient, message, channel);
143+
act(() => {
144+
dispatchMessageNewEvent(chatClient, message, channel);
148145
});
149146

150147
await waitFor(() => {
151-
expect(getNodeText(getByTestId('unread-count'))).toBe('10');
148+
expect(getByTestId('unread-count')).toHaveTextContent('10');
152149
});
153150
});
154151
});

src/utils/__tests__/Streami18n.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const customDayjsLocaleConfig = {
5757
};
5858

5959
describe('Streami18n instance - default', () => {
60-
const streami18nOptions = {};
60+
const streami18nOptions = { logger: () => {} };
6161
const streami18n = new Streami18n(streami18nOptions);
6262

6363
it('should provide default english translator', async () => {

0 commit comments

Comments
 (0)