Skip to content

Commit 8ddf919

Browse files
committed
upgrade test packages; add jest and babel configs
1 parent 54f6975 commit 8ddf919

13 files changed

+4206
-15780
lines changed

.babelrc

Lines changed: 0 additions & 3 deletions
This file was deleted.

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
language: node_js
22
node_js:
3-
- "6.9.1"
3+
- "13.8.0"
44
branches:
55
only:
66
- master
77
build:
88
run:
9-
- npm test
9+
- yarn test
1010
before_install:
1111
- pip install --user codecov
1212
after_success:

__tests__/ImageView-test.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
import React from 'react';
22
import ImageView from '../src/ImageView';
3-
import { shallow } from 'enzyme';
4-
import toJson from 'enzyme-to-json';
3+
import renderer from 'react-test-renderer';
54

65
describe('ImageView', () => {
76
describe('renders', () => {
87
test('snapshot', () => {
9-
const wrapper = shallow(<ImageView />);
10-
const tree = toJson(wrapper);
11-
expect(tree).toMatchSnapshot();
8+
const wrapper = renderer.create(<ImageView />).toJSON();
9+
expect(wrapper).toMatchSnapshot();
1210
});
1311
});
1412
});

__tests__/SimpleStepper-test.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React from 'react';
22
import SimpleStepper from '../src/SimpleStepper';
33
import { shallow } from 'enzyme';
4-
import toJson from 'enzyme-to-json';
5-
const reactNativeLogo = 'https://facebook.github.io/react-native/docs/assets/favicon.png';
4+
import renderer from 'react-test-renderer';
5+
const reactNativeLogo = 'https://reactnative.dev/docs/assets/favicon.png';
66
const STEP = {
77
increment: 'increment',
88
decrement: 'decrement',
@@ -12,13 +12,24 @@ const STEP = {
1212
describe('SimpleStepper', () => {
1313
describe('renders', () => {
1414
test('snapshot', () => {
15-
const wrapper = shallow(<SimpleStepper />);
16-
const tree = toJson(wrapper);
17-
expect(tree).toMatchSnapshot();
15+
const wrapper = renderer.create(<SimpleStepper />).toJSON();
16+
expect(wrapper).toMatchSnapshot();
17+
});
18+
test('showText with text position left to be left', () => {
19+
const wrapper = renderer.create(<SimpleStepper showText={true} position={'left'} />);
20+
expect(wrapper).toBeDefined();
21+
});
22+
test('showText with default to be text position center', () => {
23+
const wrapper = renderer.create(<SimpleStepper showText={true} />);
24+
expect(wrapper).toBeDefined();
25+
});
26+
test('showText with text position right to be right', () => {
27+
const wrapper = renderer.create(<SimpleStepper showText={true} position={'right'} />);
28+
expect(wrapper).toBeDefined();
1829
});
1930
});
2031
describe('componentDidMount', () => {});
21-
describe('componentDidReceiveProps', () => {
32+
describe('UNSAFE_componentWillReceiveProp', () => {
2233
test('test value is different', () => {
2334
const wrapper = shallow(<SimpleStepper />);
2435
wrapper.setProps({

__tests__/Step-test.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
import React from 'react';
22
import Step from '../src/Step';
3-
import { shallow } from 'enzyme';
4-
import toJson from 'enzyme-to-json';
3+
import renderer from 'react-test-renderer';
54

65
describe('Step', () => {
76
describe('renders', () => {
87
test('snapshot', () => {
9-
const wrapper = shallow(<Step />);
10-
const tree = toJson(wrapper);
11-
expect(tree).toMatchSnapshot();
8+
const wrapper = renderer.create(<Step />).toJSON();
9+
expect(wrapper).toMatchSnapshot();
1210
});
1311
test('defaultProps onPress', () => {
1412
Step.defaultProps.onPress();
@@ -18,11 +16,11 @@ describe('Step', () => {
1816
expect(Step.defaultProps.renderImage).toBeUndefined();
1917
});
2018
test('renderImage to be defined', () => {
21-
const wrapper = shallow(<Step renderImage={() => {}} />);
19+
const wrapper = renderer.create(<Step renderImage={() => {}} />);
2220
expect(wrapper).toBeDefined();
2321
});
2422
test('onPress to be defined', () => {
25-
const wrapper = shallow(<Step onPress={() => {}} />);
23+
const wrapper = renderer.create(<Step onPress={() => {}} />);
2624
expect(wrapper).toBeDefined();
2725
});
2826
});
Lines changed: 69 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`SimpleStepper renders snapshot 1`] = `
4-
<Component>
5-
<Component
4+
<View>
5+
<View
66
style={
77
Object {
88
"alignItems": "center",
@@ -15,29 +15,44 @@ exports[`SimpleStepper renders snapshot 1`] = `
1515
}
1616
}
1717
>
18-
<Step
19-
activeOpacity={0.4}
20-
disabled={true}
21-
imageOpacity={0.5}
22-
imageSource={
23-
Object {
24-
"testUri": "../../../src/assets/decrement.png",
25-
}
26-
}
27-
imageStyle={
28-
Object {
29-
"height": 36,
30-
"width": 36,
31-
}
32-
}
33-
onPress={[Function]}
18+
<View
19+
accessible={true}
20+
focusable={true}
21+
isTVSelectable={true}
22+
onClick={[Function]}
23+
onResponderGrant={[Function]}
24+
onResponderMove={[Function]}
25+
onResponderRelease={[Function]}
26+
onResponderTerminate={[Function]}
27+
onResponderTerminationRequest={[Function]}
28+
onStartShouldSetResponder={[Function]}
3429
style={
3530
Object {
31+
"opacity": 1,
3632
"padding": 8,
3733
}
3834
}
39-
/>
40-
<Component
35+
>
36+
<Image
37+
source={
38+
Object {
39+
"testUri": "../../../src/assets/decrement.png",
40+
}
41+
}
42+
style={
43+
Array [
44+
Object {
45+
"height": 36,
46+
"width": 36,
47+
},
48+
Object {
49+
"opacity": 0.5,
50+
},
51+
]
52+
}
53+
/>
54+
</View>
55+
<View
4156
style={
4257
Object {
4358
"backgroundColor": "blue",
@@ -46,28 +61,43 @@ exports[`SimpleStepper renders snapshot 1`] = `
4661
}
4762
}
4863
/>
49-
<Step
50-
activeOpacity={0.4}
51-
disabled={false}
52-
imageOpacity={1}
53-
imageSource={
54-
Object {
55-
"testUri": "../../../src/assets/increment.png",
56-
}
57-
}
58-
imageStyle={
59-
Object {
60-
"height": 36,
61-
"width": 36,
62-
}
63-
}
64-
onPress={[Function]}
64+
<View
65+
accessible={true}
66+
focusable={true}
67+
isTVSelectable={true}
68+
onClick={[Function]}
69+
onResponderGrant={[Function]}
70+
onResponderMove={[Function]}
71+
onResponderRelease={[Function]}
72+
onResponderTerminate={[Function]}
73+
onResponderTerminationRequest={[Function]}
74+
onStartShouldSetResponder={[Function]}
6575
style={
6676
Object {
77+
"opacity": 1,
6778
"padding": 8,
6879
}
6980
}
70-
/>
71-
</Component>
72-
</Component>
81+
>
82+
<Image
83+
source={
84+
Object {
85+
"testUri": "../../../src/assets/increment.png",
86+
}
87+
}
88+
style={
89+
Array [
90+
Object {
91+
"height": 36,
92+
"width": 36,
93+
},
94+
Object {
95+
"opacity": 1,
96+
},
97+
]
98+
}
99+
/>
100+
</View>
101+
</View>
102+
</View>
73103
`;
Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,37 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

33
exports[`Step renders snapshot 1`] = `
4-
<TouchableOpacity
5-
activeOpacity={1}
6-
disabled={false}
7-
onPress={[Function]}
4+
<View
5+
accessible={true}
6+
focusable={true}
7+
isTVSelectable={true}
8+
onClick={[Function]}
9+
onResponderGrant={[Function]}
10+
onResponderMove={[Function]}
11+
onResponderRelease={[Function]}
12+
onResponderTerminate={[Function]}
13+
onResponderTerminationRequest={[Function]}
14+
onStartShouldSetResponder={[Function]}
815
style={
916
Object {
17+
"opacity": 1,
1018
"padding": 8,
1119
}
1220
}
1321
>
14-
<ImageView
15-
opacity={1}
22+
<Image
1623
source={Object {}}
1724
style={
18-
Object {
19-
"height": 36,
20-
"width": 36,
21-
}
25+
Array [
26+
Object {
27+
"height": 36,
28+
"width": 36,
29+
},
30+
Object {
31+
"opacity": 1,
32+
},
33+
]
2234
}
2335
/>
24-
</TouchableOpacity>
36+
</View>
2537
`;

babel.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
presets: ["module:metro-react-native-babel-preset"],
3+
};

jest.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
verbose: true,
3+
setupFilesAfterEnv: ["<rootDir>setupTests.js"],
4+
testPathIgnorePatterns: ["/node_modules/", "/example/", "/coverage/"],
5+
preset: "react-native",
6+
coverageDirectory: "./coverage/",
7+
collectCoverage: true,
8+
};

0 commit comments

Comments
 (0)