Skip to content

Commit 5920604

Browse files
committed
chore: add missing tests
1 parent 0caf27f commit 5920604

File tree

1 file changed

+119
-83
lines changed

1 file changed

+119
-83
lines changed

src/__tests__/react-native-api.test.tsx

Lines changed: 119 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import * as React from 'react';
2-
import { FlatList, ScrollView, Switch, Text, TextInput, View } from 'react-native';
2+
import { FlatList, Image, Modal, ScrollView, Switch, Text, TextInput, View } from 'react-native';
33
import { render, screen } from '..';
44

55
/**
66
* Tests in this file are intended to give us an proactive warning that React Native behavior has
77
* changed in a way that may impact our code like queries or event handling.
88
*/
99

10-
test('React Native API assumption: <View> renders single host element', () => {
10+
test('React Native API assumption: <View> renders a single host element', () => {
1111
render(<View testID="test" />);
1212

1313
expect(screen.toJSON()).toMatchInlineSnapshot(`
@@ -17,7 +17,7 @@ test('React Native API assumption: <View> renders single host element', () => {
1717
`);
1818
});
1919

20-
test('React Native API assumption: <Text> renders single host element', () => {
20+
test('React Native API assumption: <Text> renders a single host element', () => {
2121
render(<Text testID="test">Hello</Text>);
2222

2323
expect(screen.toJSON()).toMatchInlineSnapshot(`
@@ -29,7 +29,7 @@ test('React Native API assumption: <Text> renders single host element', () => {
2929
`);
3030
});
3131

32-
test('React Native API assumption: nested <Text> renders single host element', () => {
32+
test('React Native API assumption: nested <Text> renders a single host element', () => {
3333
render(
3434
<Text testID="test">
3535
<Text testID="before">Before</Text>
@@ -63,7 +63,7 @@ test('React Native API assumption: nested <Text> renders single host element', (
6363
`);
6464
});
6565

66-
test('React Native API assumption: <TextInput> renders single host element', () => {
66+
test('React Native API assumption: <TextInput> renders a single host element', () => {
6767
render(
6868
<TextInput
6969
testID="test"
@@ -102,7 +102,7 @@ test('React Native API assumption: <TextInput> with nested Text renders single h
102102
`);
103103
});
104104

105-
test('React Native API assumption: <Switch> renders single host element', () => {
105+
test('React Native API assumption: <Switch> renders a single host element', () => {
106106
render(<Switch testID="test" value={true} onChange={jest.fn()} />);
107107

108108
expect(screen.toJSON()).toMatchInlineSnapshot(`
@@ -123,7 +123,117 @@ test('React Native API assumption: <Switch> renders single host element', () =>
123123
`);
124124
});
125125

126-
test('React Native API assumption: aria-* props render on host View', () => {
126+
test('React Native API assumption: <Image> renders a single host element', () => {
127+
render(<Image testID="test" source={{ uri: 'https://fake.url/image.jpg' }} alt="Alt text" />);
128+
129+
expect(screen.toJSON()).toMatchInlineSnapshot(`
130+
<Image
131+
alt="Alt text"
132+
source={
133+
{
134+
"uri": "https://fake.url/image.jpg",
135+
}
136+
}
137+
testID="test"
138+
/>
139+
`);
140+
});
141+
142+
test('React Native API assumption: <ScrollView> renders a single host element', () => {
143+
render(
144+
<ScrollView testID="scrollView">
145+
<View testID="view" />
146+
</ScrollView>,
147+
);
148+
149+
expect(screen.toJSON()).toMatchInlineSnapshot(`
150+
<RCTScrollView
151+
testID="scrollView"
152+
>
153+
<View>
154+
<View
155+
testID="view"
156+
/>
157+
</View>
158+
</RCTScrollView>
159+
`);
160+
});
161+
162+
test('React Native API assumption: <FlatList> renders a single host <ScrollView> element', () => {
163+
render(
164+
<FlatList testID="flatList" data={[1, 2]} renderItem={({ item }) => <Text>{item}</Text>} />,
165+
);
166+
167+
expect(screen.toJSON()).toMatchInlineSnapshot(`
168+
<RCTScrollView
169+
data={
170+
[
171+
1,
172+
2,
173+
]
174+
}
175+
getItem={[Function]}
176+
getItemCount={[Function]}
177+
keyExtractor={[Function]}
178+
onContentSizeChange={[Function]}
179+
onLayout={[Function]}
180+
onMomentumScrollBegin={[Function]}
181+
onMomentumScrollEnd={[Function]}
182+
onScroll={[Function]}
183+
onScrollBeginDrag={[Function]}
184+
onScrollEndDrag={[Function]}
185+
removeClippedSubviews={false}
186+
renderItem={[Function]}
187+
scrollEventThrottle={0.0001}
188+
stickyHeaderIndices={[]}
189+
testID="flatList"
190+
viewabilityConfigCallbackPairs={[]}
191+
>
192+
<View>
193+
<View
194+
onFocusCapture={[Function]}
195+
onLayout={[Function]}
196+
style={null}
197+
>
198+
<Text>
199+
1
200+
</Text>
201+
</View>
202+
<View
203+
onFocusCapture={[Function]}
204+
onLayout={[Function]}
205+
style={null}
206+
>
207+
<Text>
208+
2
209+
</Text>
210+
</View>
211+
</View>
212+
</RCTScrollView>
213+
`);
214+
});
215+
216+
test('React Native API assumption: <Modal> renders a single host element', () => {
217+
render(
218+
<Modal testID="test">
219+
<Text>Modal Content</Text>
220+
</Modal>,
221+
);
222+
223+
expect(screen.toJSON()).toMatchInlineSnapshot(`
224+
<Modal
225+
hardwareAccelerated={false}
226+
testID="test"
227+
visible={true}
228+
>
229+
<Text>
230+
Modal Content
231+
</Text>
232+
</Modal>
233+
`);
234+
});
235+
236+
test('React Native API assumption: aria-* props render directly on host View', () => {
127237
render(
128238
<View
129239
testID="test"
@@ -171,7 +281,7 @@ test('React Native API assumption: aria-* props render on host View', () => {
171281
`);
172282
});
173283

174-
test('React Native API assumption: aria-* props render on host Text', () => {
284+
test('React Native API assumption: aria-* props render directly on host Text', () => {
175285
render(
176286
<Text
177287
testID="test"
@@ -219,7 +329,7 @@ test('React Native API assumption: aria-* props render on host Text', () => {
219329
`);
220330
});
221331

222-
test('React Native API assumption: aria-* props render on host TextInput', () => {
332+
test('React Native API assumption: aria-* props render directly on host TextInput', () => {
223333
render(
224334
<TextInput
225335
testID="test"
@@ -266,77 +376,3 @@ test('React Native API assumption: aria-* props render on host TextInput', () =>
266376
/>
267377
`);
268378
});
269-
270-
test('ScrollView renders correctly', () => {
271-
render(
272-
<ScrollView testID="scrollView">
273-
<View testID="view" />
274-
</ScrollView>,
275-
);
276-
277-
expect(screen.toJSON()).toMatchInlineSnapshot(`
278-
<RCTScrollView
279-
testID="scrollView"
280-
>
281-
<View>
282-
<View
283-
testID="view"
284-
/>
285-
</View>
286-
</RCTScrollView>
287-
`);
288-
});
289-
290-
test('FlatList renders correctly', () => {
291-
render(
292-
<FlatList testID="flatList" data={[1, 2]} renderItem={({ item }) => <Text>{item}</Text>} />,
293-
);
294-
295-
expect(screen.toJSON()).toMatchInlineSnapshot(`
296-
<RCTScrollView
297-
data={
298-
[
299-
1,
300-
2,
301-
]
302-
}
303-
getItem={[Function]}
304-
getItemCount={[Function]}
305-
keyExtractor={[Function]}
306-
onContentSizeChange={[Function]}
307-
onLayout={[Function]}
308-
onMomentumScrollBegin={[Function]}
309-
onMomentumScrollEnd={[Function]}
310-
onScroll={[Function]}
311-
onScrollBeginDrag={[Function]}
312-
onScrollEndDrag={[Function]}
313-
removeClippedSubviews={false}
314-
renderItem={[Function]}
315-
scrollEventThrottle={0.0001}
316-
stickyHeaderIndices={[]}
317-
testID="flatList"
318-
viewabilityConfigCallbackPairs={[]}
319-
>
320-
<View>
321-
<View
322-
onFocusCapture={[Function]}
323-
onLayout={[Function]}
324-
style={null}
325-
>
326-
<Text>
327-
1
328-
</Text>
329-
</View>
330-
<View
331-
onFocusCapture={[Function]}
332-
onLayout={[Function]}
333-
style={null}
334-
>
335-
<Text>
336-
2
337-
</Text>
338-
</View>
339-
</View>
340-
</RCTScrollView>
341-
`);
342-
});

0 commit comments

Comments
 (0)