Skip to content
This repository was archived by the owner on Mar 25, 2025. It is now read-only.

Commit e23bdee

Browse files
committed
Convert Jest tests to snapshot tests.
1 parent 935a64e commit e23bdee

16 files changed

Lines changed: 2743 additions & 564 deletions

package.json

Lines changed: 11 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,48 +3,17 @@
33
"version": "0.1.2",
44
"private": true,
55
"jest": {
6-
"setupEnvScriptFile": "./node_modules/react-native/jestSupport/env.js",
7-
"haste": {
8-
"defaultPlatform": "ios",
9-
"platforms": [
10-
"ios",
11-
"android"
12-
],
13-
"providesModuleNodeModules": [
14-
"react-native"
15-
]
6+
"preset": "jest-react-native",
7+
"moduleNameMapper": {
8+
"\\.\/datepicker$": "<rootDir>/node_modules/tcomb-form-native/lib/templates/bootstrap/datepicker.ios.js"
169
},
17-
"testPathIgnorePatterns": [
18-
"/node_modules/"
10+
"preprocessorIgnorePatterns": [
11+
"node_modules/(?!react-native|tcomb-form-native|snowflake-react-native-button)"
1912
],
20-
"testFileExtensions": [
21-
"es6",
22-
"js"
23-
],
24-
"moduleFileExtensions": [
25-
"js",
26-
"json",
27-
"es6",
28-
"ios.js"
29-
],
30-
"unmockedModulePathPatterns": [
31-
"react",
32-
"react-addons-test-utils",
33-
"react-native-router-flux",
34-
"promise",
35-
"source-map",
36-
"key-mirror",
37-
"immutable",
38-
"fetch",
39-
"redux",
40-
"redux-thunk",
41-
"fbjs"
42-
],
43-
"collectCoverage": false,
4413
"verbose": true
4514
},
4615
"scripts": {
47-
"test": "rm -rf ./node_modules/jest-cli/.haste_cache && jest --no-cache",
16+
"test": "jest",
4817
"start": "react-native start",
4918
"test:watch": "npm run test -- --watch",
5019
"test-chrome": "node-debug --preload false --nodejs --harmony jest --runInBand",
@@ -55,7 +24,7 @@
5524
"immutable": "3.8.1",
5625
"key-mirror": "1.0.1",
5726
"react": "15.2.0",
58-
"react-native": "0.29.2",
27+
"react-native": "0.30.0",
5928
"react-native-navbar": "1.5.0",
6029
"react-native-router-flux": "3.31.1",
6130
"react-native-simple-store": "1.0.1",
@@ -65,18 +34,19 @@
6534
"redux": "3.5.2",
6635
"redux-thunk": "2.1.0",
6736
"regenerator": "0.8.46",
68-
"tcomb-form-native": "0.5.3",
37+
"tcomb-form-native": "0.5.3",
6938
"undefined": "0.1.0",
7039
"underscore": "1.8.3",
7140
"validate.js": "0.9.0"
7241
},
7342
"devDependencies": {
7443
"babel-core": "6.9.0",
75-
"babel-jest": "12.1.0",
44+
"babel-jest": "14.0.0",
7645
"babel-preset-react-native": "1.8.0",
7746
"docker": "0.2.14",
7847
"istanbul": "0.4.3",
79-
"jest-cli": "13.2.3",
48+
"jest": "14.0.0",
49+
"jest-react-native": "14.0.0",
8050
"react-addons-test-utils": "15.0.2",
8151
"redux-mock-store": "1.0.3",
8252
"rnpm-plugin-upgrade": "0.26.0"

src/__mocks__/react-native.js

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

src/components/__tests__/ErrorAlert-test.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@
55
*
66
* *Note:* if you want to understand the structures here, add a
77
* ```console.log``` and then ```npm test```.
8-
*
8+
*
99
*/
1010
'use strict';
1111
/**
1212
* ## Mock
1313
* Mock the simpledialog, see: 'src/__mocks__/react-native-simpledialog-android.js'
1414
*/
1515

16-
jest.autoMockOff();
1716
jest.mock('react-native-simpledialog-android');
1817

1918
/**
@@ -25,7 +24,6 @@ const SimpleAlert = require('react-native-simpledialog-android');
2524
* ## Under test
2625
* Object under test
2726
*/
28-
jest.dontMock('../ErrorAlert');
2927
var ErrorAlert = require('../ErrorAlert');
3028

3129
/**
@@ -41,7 +39,7 @@ describe('ErrorAlert', () => {
4139
error: 'Error occurred'
4240
}
4341
};
44-
42+
4543
/**
4644
* Invoke the ErrorAlert constructor and pass in the mocked
4745
* version
Lines changed: 10 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,30 @@
11
/**
22
* # FormButton-test.js
3-
*
3+
*
44
* This class tests that the form button displays correctly
55
*
66
* *Note:* if you want to understand the structures here, add a
77
* ```console.log``` and then ```npm test```.
88
*/
99
'use strict';
1010

11-
jest.autoMockOff();
12-
1311
/**
1412
* ## Imports
1513
*/
1614

17-
const React = require('react-native');
18-
const { View } = React;
15+
import 'react-native';
16+
import React from 'react';
1917

20-
const utils = require('react-addons-test-utils');
18+
import FormButton from '../FormButton';
2119

22-
/**
23-
* ## Under test
24-
* class under test
25-
*/
26-
jest.dontMock('../FormButton');
27-
var FormButton = require('../FormButton');
20+
import renderer from 'react/lib/ReactTestRenderer';
2821

29-
/**
30-
* ## Test
31-
*/
32-
describe('FormButton', () => {
33-
let formButton;
34-
35-
/**
36-
* ### defaults
37-
*/
38-
const buttonProps = {
39-
self: this,
22+
test('FormButton', () => {
23+
const props = {
4024
isDisabled: false,
4125
onPress: () => {},
4226
buttonText: 'TestString'
4327
};
44-
45-
/**
46-
* ### renderFormButton
47-
* render the component under test and return
48-
* @returns {Object} object with props, output and the renderer
49-
*/
50-
function renderFormButton(props) {
51-
const renderer = utils.createRenderer();
52-
renderer.render(<FormButton {...props}/>);
53-
const output = renderer.getRenderOutput();
54-
55-
return {
56-
props,
57-
output,
58-
renderer
59-
};
60-
}
61-
/**
62-
* ### beforeEach
63-
* before each test, render the form button with the default props
64-
*/
65-
beforeEach(() => {
66-
formButton = renderFormButton(buttonProps);
67-
});
68-
/**
69-
* ### it should be fine
70-
* the containing object should be a view
71-
*/
72-
it('should be fine', () => {
73-
const {output} = formButton;
74-
expect(output.type).toEqual(View);
75-
});
76-
77-
/**
78-
* ### it should display text
79-
* the button should be disabled and have the correct text
80-
*/
81-
it('should display text', () => {
82-
const {output} = formButton;
83-
const button = output.props.children;
84-
expect(button.props.isDisabled).toEqual(buttonProps.isDisabled);
85-
const buttonText = button.props.children;
86-
expect(buttonText).toEqual(buttonProps.buttonText);
87-
});
88-
});//describe FormButton
28+
const tree = renderer.create(<FormButton {...props} />).toJSON();
29+
expect(tree).toMatchSnapshot();
30+
});
Lines changed: 15 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* # Header-test.js
3-
*
3+
*
44
* This class tests that the Header component displays correctly
55
*
66
* *Note:* if you want to understand the structures here, add a
@@ -9,79 +9,45 @@
99
*/
1010
'use strict';
1111

12-
jest.autoMockOff();
12+
jest.mock('ActivityIndicator', () => 'ActivityIndicator');
1313

1414
/**
1515
* ## Imports
1616
*/
17-
import React, { View } from 'react-native';
18-
import utils from 'react-addons-test-utils';
17+
import 'react-native';
18+
import React from 'react';
1919

20-
/**
21-
* ## Under test
22-
* class under test
23-
*/
24-
jest.dontMock('../Header');
25-
var Header = require('../Header');
20+
import Header from '../Header';
21+
22+
import renderer from 'react/lib/ReactTestRenderer';
2623

2724
/**
2825
* ## Test
2926
*/
3027
describe('Header', () => {
31-
let header;
32-
33-
/**
34-
* ### renderHeader
35-
* display component and return
36-
* @returns {Object} with props, output and renderer
37-
*/
38-
39-
function renderHeader(props) {
40-
const renderer = utils.createRenderer();
41-
renderer.render(<Header {...props}/>);
42-
const output = renderer.getRenderOutput();
43-
44-
return {
45-
props,
46-
output,
47-
renderer
48-
};
49-
}
5028
/**
5129
* ### it should be display empty text when not fetching
5230
* render the header when not fetching
53-
*/
31+
*/
5432
it('should be display empty text when not fetching', () => {
55-
const buttonProps = {
33+
const props = {
5634
isFetching: false
5735
};
58-
header = renderHeader(buttonProps);
59-
const {output} = header;
60-
expect(output.type).toEqual(View);
61-
expect(output.props.children[0].props.children[1].props.children).toEqual(' ');
36+
const tree = renderer.create(<Header {...props} />).toJSON();
37+
expect(tree).toMatchSnapshot();
6238

6339
});
6440
/**
6541
* ### it should be display spinner when fetching
6642
* When fetching, the GiftedSpinner should display
67-
*/
43+
*/
6844
it('should be display spinner when fetching', () => {
69-
const buttonProps = {
45+
const props = {
7046
isFetching: true
7147
};
72-
header = renderHeader(buttonProps);
73-
const {output} = header;
74-
75-
expect(output.type).toEqual(View);
76-
let animating =
77-
output.props.children[0].props.children[1].props.animating;
78-
let size = output.props.children[0].props.children[1].props.size;
79-
8048

81-
expect(animating).toEqual(true);
82-
expect(size).toEqual('large');
83-
84-
//expect(output.props.children[0].props.children[1].type.displayName).toEqual('GiftedSpinner');
49+
const tree = renderer.create(<Header {...props} />).toJSON();
50+
expect(tree).toMatchSnapshot();
8551
});
8652

8753
});//describe Header

0 commit comments

Comments
 (0)