test: add tests for shallow rendering (#19)

This commit is contained in:
Michał Pierzchała
2018-10-10 17:19:50 +02:00
parent b6569a6e5d
commit 254127781c
2 changed files with 56 additions and 0 deletions
@@ -0,0 +1,31 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`shallow rendering React Test Instance 1`] = `
<TouchableOpacity
onPress={[Function]}
testID="button"
>
<Text
testID="text-button"
>
Press me
</Text>
</TouchableOpacity>
`;
exports[`shallow rendering React elements 1`] = `
<View
testID="root"
>
<TouchableOpacity
onPress={[Function]}
testID="button"
>
<Text
testID="text-button"
>
Press me
</Text>
</TouchableOpacity>
</View>
`;
+25
View File
@@ -0,0 +1,25 @@
// @flow
import React from 'react';
import { View, TouchableOpacity, Text } from '../__mocks__/reactNativeMock';
import { shallow, render } from '..';
const OnPressComponent = ({ onPress }) => (
<View testID="root">
<TouchableOpacity onPress={onPress} testID="button">
<Text testID="text-button">Press me</Text>
</TouchableOpacity>
</View>
);
test('shallow rendering React elements', () => {
const { output } = shallow(<OnPressComponent onPress={jest.fn} />);
expect(output).toMatchSnapshot();
});
test('shallow rendering React Test Instance', () => {
const { getByTestId } = render(<OnPressComponent onPress={jest.fn} />);
const { output } = shallow(getByTestId('root'));
expect(output).toMatchSnapshot();
});