Skip to content

Commit

Permalink
refactor: move render tests to RN tests file
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjastrzebski committed Aug 22, 2023
1 parent 9075365 commit e69dad4
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 14 deletions.
87 changes: 86 additions & 1 deletion src/__tests__/react-native-api.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import * as React from 'react';
import { View, Text, TextInput, Switch } from 'react-native';
import {
View,
Text,
TextInput,
Switch,
ScrollView,
FlatList,
} from 'react-native';
import { render } from '..';

/**
Expand Down Expand Up @@ -124,3 +131,81 @@ test('React Native API assumption: <Switch> renders single host element', () =>
/>
`);
});

test('ScrollView renders correctly', () => {
const screen = render(
<ScrollView testID="scrollView">
<View testID="view" />
</ScrollView>
);

expect(screen.toJSON()).toMatchInlineSnapshot(`
<RCTScrollView
testID="scrollView"
>
<View>
<View
testID="view"
/>
</View>
</RCTScrollView>
`);
});

test('FlatList renders correctly', () => {
const screen = render(
<FlatList
testID="flatList"
data={[1, 2]}
renderItem={({ item }) => <Text>{item}</Text>}
/>
);

expect(screen.toJSON()).toMatchInlineSnapshot(`
<RCTScrollView
data={
[
1,
2,
]
}
getItem={[Function]}
getItemCount={[Function]}
keyExtractor={[Function]}
onContentSizeChange={[Function]}
onLayout={[Function]}
onMomentumScrollBegin={[Function]}
onMomentumScrollEnd={[Function]}
onScroll={[Function]}
onScrollBeginDrag={[Function]}
onScrollEndDrag={[Function]}
removeClippedSubviews={false}
renderItem={[Function]}
scrollEventThrottle={50}
stickyHeaderIndices={[]}
testID="flatList"
viewabilityConfigCallbackPairs={[]}
>
<View>
<View
onFocusCapture={[Function]}
onLayout={[Function]}
style={null}
>
<Text>
1
</Text>
</View>
<View
onFocusCapture={[Function]}
onLayout={[Function]}
style={null}
>
<Text>
2
</Text>
</View>
</View>
</RCTScrollView>
`);
});
14 changes: 1 addition & 13 deletions src/__tests__/render.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-console */
import * as React from 'react';
import { View, Text, TextInput, Pressable, FlatList } from 'react-native';
import { View, Text, TextInput, Pressable } from 'react-native';
import { getConfig, resetToDefaults } from '../config';
import { render, screen, fireEvent, RenderAPI } from '..';

Expand Down Expand Up @@ -254,15 +254,3 @@ test('render calls detects host component names', () => {
render(<View testID="test" />);
expect(getConfig().hostComponentNames).not.toBeUndefined();
});

test('render FlatList', () => {
const screen = render(
<FlatList
testID="flatList"
data={[1, 2, 3]}
renderItem={({ item }) => <Text>{item}</Text>}
/>
);

expect(screen.getByTestId('flatList')).toBeTruthy();
});

0 comments on commit e69dad4

Please sign in to comment.