Skip to content

test: add tests for shallow rendering #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/__tests__/__snapshots__/shallow.test.js.snap
Original file line number Diff line number Diff line change
@@ -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 changes: 25 additions & 0 deletions src/__tests__/shallow.test.js
Original file line number Diff line number Diff line change
@@ -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();
});