Skip to content

Commit b2c5bee

Browse files
author
Dan Carbonell
committed
RTL upgrade
1 parent 10f9455 commit b2c5bee

File tree

8 files changed

+714
-656
lines changed

8 files changed

+714
-656
lines changed

jest.config.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
const jestPreset = require('@testing-library/react-native/jest-preset');
2-
3-
module.exports = Object.assign(jestPreset, {
1+
// eslint-disable-next-line no-undef
2+
module.exports = {
3+
verbose: true,
44
testRegex: [
55
/**
66
* If you want to test single file, mention it here
@@ -9,11 +9,13 @@ module.exports = Object.assign(jestPreset, {
99
* "src/components/MessageList/__tests__/MessageList.test.js"
1010
*/
1111
],
12-
testPathIgnorePatterns: ['/node_modules/', '/examples/', '__snapshots__'],
1312
moduleNameMapper: {
1413
'mock-builders(.*)$': '<rootDir>/src/mock-builders$1',
1514
'@stream-io/styled-components':
1615
'<rootDir>/node_modules/@stream-io/styled-components/native/dist/styled-components.native.cjs.js',
1716
},
18-
setupFiles: [...jestPreset.setupFiles, require.resolve('./jest-setup.js')],
19-
});
17+
preset: 'react-native',
18+
setupFiles: [require.resolve('./jest-setup.js')],
19+
setupFilesAfterEnv: ['@testing-library/jest-native/extend-expect'],
20+
testPathIgnorePatterns: ['/node_modules/', '/examples/', '__snapshots__'],
21+
};

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
"@babel/preset-flow": "^7.10.4",
105105
"@babel/preset-react": "^7.0.0",
106106
"@testing-library/jest-native": "^3.3.0",
107-
"@testing-library/react-native": "^5.0.3",
107+
"@testing-library/react-native": "^7.0.1",
108108
"@types/react": "^16.8.23",
109109
"@types/react-native": "^0.57.0",
110110
"ast-pretty-print": "^2.0.1",
@@ -116,11 +116,11 @@
116116
"babel-preset-expo": "^5.0.0",
117117
"eslint": "^5.16.0",
118118
"eslint-plugin-babel": "^5.3.0",
119-
"eslint-plugin-jest": "^22.5.1",
119+
"eslint-plugin-jest": "^23.20.0",
120120
"eslint-plugin-markdown": "^1.0.0",
121121
"eslint-plugin-react": "^7.12.4",
122122
"husky": "^2.1.0",
123-
"jest": "^25.1.0",
123+
"jest": "^26.2.2",
124124
"prettier": "^1.16.4",
125125
"react": "^16.5.0",
126126
"react-dom": "^16.8.6",

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

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
import React from 'react';
2-
import {
3-
fireEvent,
4-
render,
5-
wait,
6-
waitForElement,
7-
} from '@testing-library/react-native';
8-
import '@testing-library/jest-native/extend-expect';
2+
import { fireEvent, render, waitFor } from '@testing-library/react-native';
93
import { v4 as uuidv4 } from 'uuid';
104

115
import {
@@ -29,7 +23,7 @@ describe('Attachment', () => {
2923
const attachment = generateAudioAttachment();
3024
const { getByTestId } = render(getAttachmentComponent({ attachment }));
3125

32-
await wait(() => {
26+
await waitFor(() => {
3327
expect(getByTestId('file-attachment')).toBeTruthy();
3428
});
3529
});
@@ -38,7 +32,7 @@ describe('Attachment', () => {
3832
const attachment = generateFileAttachment();
3933
const { getByTestId } = render(getAttachmentComponent({ attachment }));
4034

41-
await wait(() => {
35+
await waitFor(() => {
4236
expect(getByTestId('file-attachment')).toBeTruthy();
4337
});
4438
});
@@ -47,7 +41,7 @@ describe('Attachment', () => {
4741
const attachment = generateImgurAttachment();
4842
const { getByTestId } = render(getAttachmentComponent({ attachment }));
4943

50-
await wait(() => {
44+
await waitFor(() => {
5145
expect(getByTestId('card-attachment')).toBeTruthy();
5246
});
5347
});
@@ -56,7 +50,7 @@ describe('Attachment', () => {
5650
const attachment = generateGiphyAttachment();
5751
const { getByTestId } = render(getAttachmentComponent({ attachment }));
5852

59-
await wait(() => {
53+
await waitFor(() => {
6054
expect(getByTestId('card-attachment')).toBeTruthy();
6155
});
6256
});
@@ -65,7 +59,7 @@ describe('Attachment', () => {
6559
const attachment = generateImageAttachment();
6660
const { getByTestId } = render(getAttachmentComponent({ attachment }));
6761

68-
await wait(() => {
62+
await waitFor(() => {
6963
expect(getByTestId('card-attachment')).toBeTruthy();
7064
});
7165
});
@@ -77,7 +71,7 @@ describe('Attachment', () => {
7771
});
7872
const { getByTestId } = render(getAttachmentComponent({ attachment }));
7973

80-
await wait(() => {
74+
await waitFor(() => {
8175
expect(getByTestId('image-attachment-single')).toBeTruthy();
8276
});
8377
});
@@ -91,7 +85,7 @@ describe('Attachment', () => {
9185
getAttachmentComponent({ attachment, actionHandler: () => {} }),
9286
);
9387

94-
await wait(() => {
88+
await waitFor(() => {
9589
expect(getByTestId('attachment-actions')).toBeTruthy();
9690
});
9791
});
@@ -106,7 +100,7 @@ describe('Attachment', () => {
106100
}),
107101
);
108102

109-
await waitForElement(() =>
103+
await waitFor(() =>
110104
getByTestId(`attachment-actions-button-${action.name}`),
111105
);
112106

@@ -117,7 +111,7 @@ describe('Attachment', () => {
117111
fireEvent.press(getByTestId(`attachment-actions-button-${action.name}`));
118112
fireEvent.press(getByTestId(`attachment-actions-button-${action.name}`));
119113

120-
await wait(() => {
114+
await waitFor(() => {
121115
expect(actionHandler).toHaveBeenCalledTimes(2);
122116
});
123117
});
@@ -128,7 +122,7 @@ describe('Attachment', () => {
128122
attachment: generateCardAttachment({ type: uuidv4() }),
129123
}),
130124
);
131-
await wait(() => {
125+
await waitFor(() => {
132126
expect(getByTestId('card-attachment')).toBeTruthy();
133127
});
134128
});

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

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

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

@@ -9,7 +9,7 @@ describe('Avatar', () => {
99
<Avatar image='https://pbs.twimg.com/profile_images/897621870069112832/dFGq6aiE_400x400.jpg' />,
1010
);
1111

12-
await wait(() => {
12+
await waitFor(() => {
1313
expect(queryByTestId('avatar-image')).toBeTruthy();
1414
expect(queryByTestId('avatar-text')).toBeFalsy();
1515
});
@@ -23,7 +23,7 @@ describe('Avatar', () => {
2323
/>,
2424
);
2525

26-
await wait(() => {
26+
await waitFor(() => {
2727
expect(queryByTestId('avatar-image')).toBeTruthy();
2828
expect(queryByTestId('avatar-text')).toBeFalsy();
2929
});
@@ -37,7 +37,7 @@ describe('Avatar', () => {
3737
/>,
3838
);
3939

40-
await wait(() => {
40+
await waitFor(() => {
4141
expect(queryByTestId('avatar-image')).toBeTruthy();
4242
expect(queryByTestId('avatar-text')).toBeFalsy();
4343
});
@@ -46,7 +46,7 @@ describe('Avatar', () => {
4646
it('should render an avatar with no image but a name and default size', async () => {
4747
const { getByTestId, queryByTestId } = render(<Avatar name='Test User' />);
4848

49-
await wait(() => {
49+
await waitFor(() => {
5050
expect(queryByTestId('avatar-image')).toBeFalsy();
5151
expect(queryByTestId('avatar-text')).toBeTruthy();
5252
expect(getNodeText(getByTestId('avatar-text'))).toBe('TU');
@@ -58,7 +58,7 @@ describe('Avatar', () => {
5858
<Avatar name='Test User' size={20} />,
5959
);
6060

61-
await wait(() => {
61+
await waitFor(() => {
6262
expect(queryByTestId('avatar-image')).toBeFalsy();
6363
expect(queryByTestId('avatar-text')).toBeTruthy();
6464
expect(getNodeText(getByTestId('avatar-text'))).toBe('TU');

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

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import {
33
act,
44
getNodeText,
55
render,
6-
wait,
7-
waitForElement,
6+
waitFor,
87
} from '@testing-library/react-native';
98

109
import {
@@ -77,7 +76,7 @@ describe('ChannelPreview', () => {
7776
});
7877
await initializeChannel(c);
7978
const { queryByText } = render(getComponent());
80-
await waitForElement(() => queryByText(message.text));
79+
await waitFor(() => queryByText(message.text));
8180
});
8281

8382
it('should mark channel as read, when message.read event is received for current user', async () => {
@@ -87,13 +86,13 @@ describe('ChannelPreview', () => {
8786

8887
const { getByTestId } = render(getComponent());
8988

90-
await waitForElement(() => getByTestId('channel-id'));
89+
await waitFor(() => getByTestId('channel-id'));
9190
expect(getNodeText(getByTestId('unread-count'))).toBe('20');
92-
act(() => {
93-
dispatchMessageReadEvent(chatClient, clientUser, channel);
91+
await act(async () => {
92+
await dispatchMessageReadEvent(chatClient, clientUser, channel);
9493
});
9594

96-
await wait(() => {
95+
await waitFor(() => {
9796
expect(getNodeText(getByTestId('unread-count'))).toBe('0');
9897
});
9998
});
@@ -112,17 +111,17 @@ describe('ChannelPreview', () => {
112111

113112
const { getByTestId } = render(getComponent());
114113

115-
await waitForElement(() => getByTestId('channel-id'));
114+
await waitFor(() => getByTestId('channel-id'));
116115

117116
const message = generateMessage({
118117
user: clientUser,
119118
});
120119

121-
act(() => {
122-
dispatcher(chatClient, message, channel);
120+
await act(async () => {
121+
await dispatcher(chatClient, message, channel);
123122
});
124123

125-
await wait(() => {
124+
await waitFor(() => {
126125
expect(getNodeText(getByTestId('last-event-message'))).toBe(
127126
message.text,
128127
);
@@ -136,19 +135,19 @@ describe('ChannelPreview', () => {
136135

137136
const { getByTestId } = render(getComponent());
138137

139-
await waitForElement(() => getByTestId('channel-id'));
138+
await waitFor(() => getByTestId('channel-id'));
140139

141140
const message = generateMessage({
142141
user: clientUser,
143142
});
144143

145144
channel.countUnread = () => 10;
146145

147-
act(() => {
148-
dispatchMessageNewEvent(chatClient, message, channel);
146+
await act(async () => {
147+
await dispatchMessageNewEvent(chatClient, message, channel);
149148
});
150149

151-
await wait(() => {
150+
await waitFor(() => {
152151
expect(getNodeText(getByTestId('unread-count'))).toBe('10');
153152
});
154153
});

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

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
import React from 'react';
2-
import {
3-
fireEvent,
4-
render,
5-
wait,
6-
waitForElement,
7-
} from '@testing-library/react-native';
2+
import { fireEvent, render, waitFor } from '@testing-library/react-native';
83
import { v4 as uuidv4 } from 'uuid';
94
import truncate from 'lodash/truncate';
105

@@ -66,10 +61,10 @@ describe('ChannelPreviewMessenger', () => {
6661
}),
6762
);
6863

69-
await waitForElement(() => getByTestId('channel-preview-button'));
64+
await waitFor(() => getByTestId('channel-preview-button'));
7065
fireEvent.press(getByTestId('channel-preview-button'));
7166

72-
await wait(() => {
67+
await waitFor(() => {
7368
// eslint-disable-next-line jest/prefer-called-with
7469
expect(setActiveChannel).toHaveBeenCalledTimes(1);
7570
});
@@ -85,7 +80,7 @@ describe('ChannelPreviewMessenger', () => {
8580
}),
8681
);
8782
const { queryByText } = render(getComponent());
88-
await waitForElement(() => queryByText(channelName));
83+
await waitFor(() => queryByText(channelName));
8984
});
9085

9186
it('should render comma separated names of other members, if channel has no name', async () => {
@@ -102,7 +97,7 @@ describe('ChannelPreviewMessenger', () => {
10297
const { queryByText } = render(getComponent());
10398
const expectedDisplayName = `${m1.user.name}, ${m2.user.name}, ${m3.user.name}`;
10499

105-
await waitForElement(() => queryByText(expectedDisplayName));
100+
await waitFor(() => queryByText(expectedDisplayName));
106101
});
107102

108103
it('should render latest message, truncated to length given by latestMessageLength', async () => {
@@ -117,6 +112,6 @@ describe('ChannelPreviewMessenger', () => {
117112
);
118113

119114
const expectedMessagePreview = truncate(message.text, { length: 6 });
120-
await waitForElement(() => queryByText(expectedMessagePreview));
115+
await waitFor(() => queryByText(expectedMessagePreview));
121116
});
122117
});
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import React from 'react';
2-
import { render, wait } from '@testing-library/react-native';
2+
import { render, waitFor } from '@testing-library/react-native';
33

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

66
describe('CloseButton', () => {
77
it('should render a CloseButton', async () => {
88
const { queryByTestId } = render(<CloseButton />);
99

10-
await wait(() => expect(queryByTestId('close-button')).toBeTruthy());
10+
await waitFor(() => expect(queryByTestId('close-button')).toBeTruthy());
1111
});
1212
});

0 commit comments

Comments
 (0)