Skip to content

Commit 45c097b

Browse files
committed
feat: update testing library to v9 and fix broken tests after update to 0.67
1 parent cf9e2b3 commit 45c097b

File tree

15 files changed

+344
-252
lines changed

15 files changed

+344
-252
lines changed

package/native-package/yarn.lock

Lines changed: 156 additions & 79 deletions
Large diffs are not rendered by default.

package/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,9 @@
9696
"@react-native-community/eslint-config": "2.0.0",
9797
"@react-native-community/eslint-plugin": "1.1.0",
9898
"@react-native-community/netinfo": "6.0.0",
99-
"@testing-library/jest-native": "4.0.1",
100-
"@testing-library/react-native": "7.2.0",
99+
"@testing-library/jest-native": "4.0.4",
100+
"@testing-library/react-native": "9.0.0",
101+
"@testing-library/react-hooks": "7.0.2",
101102
"@types/eslint": "7.2.10",
102103
"@types/jest": "26.0.23",
103104
"@types/lodash": "4.14.169",

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,11 @@ export const ImageGalleryHeader = <
177177
centerElement({ hideOverlay, photo })
178178
) : (
179179
<View style={[styles.centerContainer, centerContainer]}>
180-
<Text style={[styles.userName, { color: black }, usernameText]}>
180+
<Text
181+
accessibilityLabel={photo?.user?.name || t('Unknown User')}
182+
accessible={true}
183+
style={[styles.userName, { color: black }, usernameText]}
184+
>
181185
{photo?.user?.name || t('Unknown User')}
182186
</Text>
183187
{date && <Text style={[styles.date, { color: black }, dateText]}>{date}</Text>}

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,38 @@
11
import React from 'react';
2-
32
import type Animated from 'react-native-reanimated';
3+
import { useSharedValue } from 'react-native-reanimated';
4+
5+
import { renderHook } from '@testing-library/react-hooks';
46

57
import { render } from '@testing-library/react-native';
68

79
import { ThemeProvider } from '../../../../contexts/themeContext/ThemeContext';
10+
811
import { ImageGalleryHeader } from '../ImageGalleryHeader';
912

1013
it('doesnt fail if fromNow is not available on first render', () => {
1114
try {
12-
const { getAllByText } = render(
15+
let sharedValueOpacity: Animated.SharedValue<number>;
16+
let sharedValueVisible: Animated.SharedValue<number>;
17+
renderHook(() => {
18+
sharedValueOpacity = useSharedValue(1);
19+
sharedValueVisible = useSharedValue(1);
20+
});
21+
const { getAllByA11yLabel } = render(
1322
<ThemeProvider>
1423
<ImageGalleryHeader
15-
opacity={1 as unknown as Animated.SharedValue<number>}
24+
// @ts-ignore
25+
opacity={sharedValueOpacity}
1626
photo={{
1727
id: 'id',
1828
uri: 'file:///bogus/uri/to/photo.jpg',
1929
}}
20-
visible={1 as unknown as Animated.SharedValue<number>}
30+
// @ts-ignore
31+
visible={sharedValueVisible}
2132
/>
2233
</ThemeProvider>,
2334
);
24-
25-
expect(getAllByText('Unknown User')).toBeTruthy();
35+
expect(getAllByA11yLabel('Unknown User')).toBeTruthy();
2636
} catch (error: unknown) {
2737
if (error instanceof Error) {
2838
throw new Error(`Error encountered on first render of ImageGalleryHeader: ${error.message}`);

package/src/components/Message/MessageSimple/__tests__/__snapshots__/MessageReplies.test.js.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ exports[`MessageReplies should render message replies 1`] = `
4747
</View>
4848
<View
4949
accessible={true}
50+
collapsable={false}
5051
focusable={true}
5152
onClick={[Function]}
5253
onResponderGrant={[Function]}
Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import React from 'react';
22
import { Text } from 'react-native';
33

4-
import { render, waitFor } from '@testing-library/react-native';
4+
import { render, waitFor, within } from '@testing-library/react-native';
55

66
// @ts-ignore
77
import { ASTNode, SingleASTNode } from 'simple-markdown';
88

99
import { ListOutput, ListOutputProps } from './renderText';
10+
import type { ReactTestInstance } from 'react-test-renderer';
1011

1112
describe('list', () => {
1213
const createNode = ({
@@ -31,40 +32,45 @@ describe('list', () => {
3132
</>
3233
);
3334

34-
it('renders numbered items', async () => {
35+
it('renders numbered items', () => {
3536
const node = createNode({ amount: 3, ordered: true, start: 1 });
36-
const { getByText } = render(<MockText node={node} output={mockOutput} state={{}} />);
37-
38-
await waitFor(() => expect(getByText('1. ')).toBeTruthy());
39-
await waitFor(() => expect(getByText('2. ')).toBeTruthy());
40-
await waitFor(() => expect(getByText('3. ')).toBeTruthy());
37+
const { container } = render(<MockText node={node} output={mockOutput} state={{}} />);
38+
const textInstances = container.children as ReactTestInstance[];
39+
textInstances.forEach(async (instance, index) => {
40+
const text = `${index + node.start}. `; // 1. , 2. ...
41+
await waitFor(() => expect(within(instance).getByText(text)).toBeTruthy());
42+
});
4143
});
4244

43-
it('renders numbered items from a start index', async () => {
45+
it('renders numbered items from a start index', () => {
4446
const node = createNode({ amount: 3, ordered: true, start: 3 });
45-
const { getByText } = render(<MockText node={node} output={mockOutput} state={{}} />);
46-
47-
await waitFor(() => expect(getByText('3. ')).toBeTruthy());
48-
await waitFor(() => expect(getByText('4. ')).toBeTruthy());
49-
await waitFor(() => expect(getByText('5. ')).toBeTruthy());
47+
const { container } = render(<MockText node={node} output={mockOutput} state={{}} />);
48+
const textInstances = container.children as ReactTestInstance[];
49+
textInstances.forEach(async (instance, index) => {
50+
const text = `${index + node.start}. `; // 3. , 4. ...
51+
await waitFor(() => expect(within(instance).getByText(text)).toBeTruthy());
52+
});
5053
});
5154

52-
it('does not throw an error if an item is empty', async () => {
55+
it('does not throw an error if an item is empty', () => {
5356
const node = {
5457
...createNode({ amount: 3, ordered: true }),
5558
items: ['Not empty', null, 'Not empty'],
5659
};
57-
const { getByText } = render(<MockText node={node} output={mockOutput} state={{}} />);
58-
59-
await waitFor(() => expect(getByText('1. ')).toBeTruthy());
60-
await waitFor(() => expect(getByText('2. ')).toBeTruthy());
61-
await waitFor(() => expect(getByText('3. ')).toBeTruthy());
60+
const { container } = render(<MockText node={node} output={mockOutput} state={{}} />);
61+
const textInstances = container.children as ReactTestInstance[];
62+
textInstances.forEach(async (instance, index) => {
63+
const text = `${index + 1}. `; // 1. , 2. ...
64+
await waitFor(() => expect(within(instance).getByText(text)).toBeTruthy());
65+
});
6266
});
6367

64-
it('renders an unordered list', async () => {
68+
it('renders an unordered list', () => {
6569
const node = createNode({ amount: 3 });
66-
const { getAllByText } = render(<MockText node={node} output={mockOutput} state={{}} />);
67-
68-
await waitFor(() => expect(getAllByText('\u2022 ')).toHaveLength(3));
70+
const { container } = render(<MockText node={node} output={mockOutput} state={{}} />);
71+
const textInstances = container.children as ReactTestInstance[];
72+
textInstances.forEach(async (instance) => {
73+
await waitFor(() => expect(within(instance).getByText('\u2022 ')).toBeTruthy());
74+
});
6975
});
7076
});

package/src/components/MessageInput/__tests__/__snapshots__/AttachButton.test.js.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ exports[`AttachButton should render a disabled AttachButton 1`] = `
2020
>
2121
<View
2222
accessible={true}
23+
collapsable={false}
2324
hitSlop={
2425
Object {
2526
"bottom": 15,
@@ -100,6 +101,7 @@ exports[`AttachButton should render an enabled AttachButton 1`] = `
100101
>
101102
<View
102103
accessible={true}
104+
collapsable={false}
103105
hitSlop={
104106
Object {
105107
"bottom": 15,

0 commit comments

Comments
 (0)