mirror of
https://github.com/callstack/react-native-testing-library.git
synced 2026-09-18 23:09:04 +08:00
test: add tests for shallow rendering (#19)
This commit is contained in:
@@ -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>
|
||||
`;
|
||||
@@ -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();
|
||||
});
|
||||
Reference in New Issue
Block a user