Skip to content

Commit 2541277

Browse files
committed
test: add tests for shallow rendering (#19)
1 parent b6569a6 commit 2541277

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`shallow rendering React Test Instance 1`] = `
4+
<TouchableOpacity
5+
onPress={[Function]}
6+
testID="button"
7+
>
8+
<Text
9+
testID="text-button"
10+
>
11+
Press me
12+
</Text>
13+
</TouchableOpacity>
14+
`;
15+
16+
exports[`shallow rendering React elements 1`] = `
17+
<View
18+
testID="root"
19+
>
20+
<TouchableOpacity
21+
onPress={[Function]}
22+
testID="button"
23+
>
24+
<Text
25+
testID="text-button"
26+
>
27+
Press me
28+
</Text>
29+
</TouchableOpacity>
30+
</View>
31+
`;

src/__tests__/shallow.test.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// @flow
2+
import React from 'react';
3+
import { View, TouchableOpacity, Text } from '../__mocks__/reactNativeMock';
4+
import { shallow, render } from '..';
5+
6+
const OnPressComponent = ({ onPress }) => (
7+
<View testID="root">
8+
<TouchableOpacity onPress={onPress} testID="button">
9+
<Text testID="text-button">Press me</Text>
10+
</TouchableOpacity>
11+
</View>
12+
);
13+
14+
test('shallow rendering React elements', () => {
15+
const { output } = shallow(<OnPressComponent onPress={jest.fn} />);
16+
17+
expect(output).toMatchSnapshot();
18+
});
19+
20+
test('shallow rendering React Test Instance', () => {
21+
const { getByTestId } = render(<OnPressComponent onPress={jest.fn} />);
22+
const { output } = shallow(getByTestId('root'));
23+
24+
expect(output).toMatchSnapshot();
25+
});

0 commit comments

Comments
 (0)