Skip to content

Commit

Permalink
fix RN test
Browse files Browse the repository at this point in the history
  • Loading branch information
SimenB committed Aug 28, 2019
1 parent 5fc793c commit 823dced
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 42 deletions.
86 changes: 62 additions & 24 deletions examples/react-native/__tests__/__snapshots__/intro.test.js.snap
Expand Up @@ -45,6 +45,67 @@ exports[`renders the ActivityIndicator component 1`] = `
/>
`;

exports[`renders the FlatList component 1`] = `
<RCTScrollView
data={
Array [
"apple",
"banana",
"kiwi",
]
}
disableVirtualization={false}
getItem={[Function]}
getItemCount={[Function]}
horizontal={false}
initialNumToRender={10}
keyExtractor={[Function]}
maxToRenderPerBatch={10}
numColumns={1}
onContentSizeChange={[Function]}
onEndReachedThreshold={2}
onLayout={[Function]}
onMomentumScrollEnd={[Function]}
onScroll={[Function]}
onScrollBeginDrag={[Function]}
onScrollEndDrag={[Function]}
removeClippedSubviews={false}
renderItem={[Function]}
scrollEventThrottle={50}
stickyHeaderIndices={Array []}
updateCellsBatchingPeriod={50}
viewabilityConfigCallbackPairs={Array []}
windowSize={21}
>
<View>
<View
onLayout={[Function]}
style={null}
>
<Text>
apple
</Text>
</View>
<View
onLayout={[Function]}
style={null}
>
<Text>
banana
</Text>
</View>
<View
onLayout={[Function]}
style={null}
>
<Text>
kiwi
</Text>
</View>
</View>
</RCTScrollView>
`;

exports[`renders the Image component 1`] = `
<Image
style={
Expand All @@ -56,34 +117,11 @@ exports[`renders the Image component 1`] = `
/>
`;

exports[`renders the ListView component 1`] = `
<RCTScrollView
dataSource={
ListViewDataSource {
"items": 3,
}
}
renderRow={[Function]}
renderScrollComponent={[Function]}
>
<View>
<Text>
apple
</Text>
<Text>
banana
</Text>
<Text>
kiwi
</Text>
</View>
</RCTScrollView>
`;

exports[`renders the TextInput component 1`] = `
<TextInput
allowFontScaling={true}
autoCorrect={false}
rejectResponderTermination={true}
underlineColorAndroid="transparent"
value="apple banana kiwi"
/>
Expand Down
31 changes: 13 additions & 18 deletions examples/react-native/__tests__/intro.test.js
Expand Up @@ -4,14 +4,16 @@
* Sample React Native Snapshot Test
*/

'use strict';

import 'react-native';
import React from 'react';
import Intro from '../Intro';

// Note: test renderer must be required after react-native.
import {
ActivityIndicator,
FlatList,
Image,
Text,
TextInput,
} from 'react-native';
import renderer from 'react-test-renderer';
import Intro from '../Intro';

jest.setTimeout(15000);

Expand All @@ -22,15 +24,13 @@ it('renders correctly', () => {

// These serve as integration tests for the jest-react-native preset.
it('renders the ActivityIndicator component', () => {
const ActivityIndicator = require('ActivityIndicator');
const tree = renderer
.create(<ActivityIndicator animating={true} size="small" />)
.toJSON();
expect(tree).toMatchSnapshot();
});

it('renders the Image component', done => {
const Image = require('Image');
Image.getSize('path.jpg', (width, height) => {
const tree = renderer.create(<Image style={{height, width}} />).toJSON();
expect(tree).toMatchSnapshot();
Expand All @@ -39,24 +39,19 @@ it('renders the Image component', done => {
});

it('renders the TextInput component', () => {
const TextInput = require('TextInput');
const tree = renderer
.create(<TextInput autoCorrect={false} value="apple banana kiwi" />)
.toJSON();
expect(tree).toMatchSnapshot();
});

it('renders the ListView component', () => {
const ListView = require('ListView');
const Text = require('Text');
const dataSource = new ListView.DataSource({
rowHasChanged: (r1, r2) => r1 !== r2,
}).cloneWithRows(['apple', 'banana', 'kiwi']);
it('renders the FlatList component', () => {
const tree = renderer
.create(
<ListView
dataSource={dataSource}
renderRow={rowData => <Text>{rowData}</Text>}
<FlatList
data={['apple', 'banana', 'kiwi']}
keyExtractor={item => item}
renderItem={({item}) => <Text>{item}</Text>}
/>
)
.toJSON();
Expand Down

0 comments on commit 823dced

Please sign in to comment.