Skip to content

Commit e69dad4

Browse files
committed
refactor: move render tests to RN tests file
1 parent 9075365 commit e69dad4

File tree

2 files changed

+87
-14
lines changed

2 files changed

+87
-14
lines changed

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

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import * as React from 'react';
2-
import { View, Text, TextInput, Switch } from 'react-native';
2+
import {
3+
View,
4+
Text,
5+
TextInput,
6+
Switch,
7+
ScrollView,
8+
FlatList,
9+
} from 'react-native';
310
import { render } from '..';
411

512
/**
@@ -124,3 +131,81 @@ test('React Native API assumption: <Switch> renders single host element', () =>
124131
/>
125132
`);
126133
});
134+
135+
test('ScrollView renders correctly', () => {
136+
const screen = render(
137+
<ScrollView testID="scrollView">
138+
<View testID="view" />
139+
</ScrollView>
140+
);
141+
142+
expect(screen.toJSON()).toMatchInlineSnapshot(`
143+
<RCTScrollView
144+
testID="scrollView"
145+
>
146+
<View>
147+
<View
148+
testID="view"
149+
/>
150+
</View>
151+
</RCTScrollView>
152+
`);
153+
});
154+
155+
test('FlatList renders correctly', () => {
156+
const screen = render(
157+
<FlatList
158+
testID="flatList"
159+
data={[1, 2]}
160+
renderItem={({ item }) => <Text>{item}</Text>}
161+
/>
162+
);
163+
164+
expect(screen.toJSON()).toMatchInlineSnapshot(`
165+
<RCTScrollView
166+
data={
167+
[
168+
1,
169+
2,
170+
]
171+
}
172+
getItem={[Function]}
173+
getItemCount={[Function]}
174+
keyExtractor={[Function]}
175+
onContentSizeChange={[Function]}
176+
onLayout={[Function]}
177+
onMomentumScrollBegin={[Function]}
178+
onMomentumScrollEnd={[Function]}
179+
onScroll={[Function]}
180+
onScrollBeginDrag={[Function]}
181+
onScrollEndDrag={[Function]}
182+
removeClippedSubviews={false}
183+
renderItem={[Function]}
184+
scrollEventThrottle={50}
185+
stickyHeaderIndices={[]}
186+
testID="flatList"
187+
viewabilityConfigCallbackPairs={[]}
188+
>
189+
<View>
190+
<View
191+
onFocusCapture={[Function]}
192+
onLayout={[Function]}
193+
style={null}
194+
>
195+
<Text>
196+
1
197+
</Text>
198+
</View>
199+
<View
200+
onFocusCapture={[Function]}
201+
onLayout={[Function]}
202+
style={null}
203+
>
204+
<Text>
205+
2
206+
</Text>
207+
</View>
208+
</View>
209+
</RCTScrollView>
210+
`);
211+
});

src/__tests__/render.test.tsx

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable no-console */
22
import * as React from 'react';
3-
import { View, Text, TextInput, Pressable, FlatList } from 'react-native';
3+
import { View, Text, TextInput, Pressable } from 'react-native';
44
import { getConfig, resetToDefaults } from '../config';
55
import { render, screen, fireEvent, RenderAPI } from '..';
66

@@ -254,15 +254,3 @@ test('render calls detects host component names', () => {
254254
render(<View testID="test" />);
255255
expect(getConfig().hostComponentNames).not.toBeUndefined();
256256
});
257-
258-
test('render FlatList', () => {
259-
const screen = render(
260-
<FlatList
261-
testID="flatList"
262-
data={[1, 2, 3]}
263-
renderItem={({ item }) => <Text>{item}</Text>}
264-
/>
265-
);
266-
267-
expect(screen.getByTestId('flatList')).toBeTruthy();
268-
});

0 commit comments

Comments
 (0)