jest tests setup

This commit is contained in:
Martin Bielik 2016-05-17 12:52:47 +02:00
parent bd8d684baf
commit 9c2bb2a5a6
6 changed files with 98 additions and 3 deletions

View File

@ -26,7 +26,9 @@
"before": true,
"beforeEach": true,
"after": true,
"afterEach": true
"afterEach": true,
"jest": true,
"expect": true
},
"rules": {

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
node_modules
*-key.keystore
npm-debug.log
coverage

35
__mocks__/react-native.js vendored Normal file
View File

@ -0,0 +1,35 @@
const React = require('react');
const ReactNative = React;
ReactNative.StyleSheet = {
create: function create(styles) {
return styles;
}
};
class View extends React.Component {
render() { return false; }
}
class ListView extends React.Component {
static DataSource() {
}
}
class AppRegistry {
static registerComponent () {
}
}
ReactNative.View = View;
ReactNative.ScrollView = View;
ReactNative.ListView = ListView;
ReactNative.Text = View;
ReactNative.TouchableOpacity = View;
ReactNative.TouchableHighlight = View;
ReactNative.TouchableWithoutFeedback = View;
ReactNative.ToolbarAndroid = View;
ReactNative.Image = View;
ReactNative.AppRegistry = AppRegistry;
module.exports = ReactNative;

View File

@ -0,0 +1,20 @@
import React from 'react';
import { View } from 'react-native';
import utils from 'react-addons-test-utils';
jest.dontMock('./HelloComponent');
const HelloComponent = require('./HelloComponent').default;
describe('HelloComponent', () => {
it('should render hello world', () => {
const renderer = utils.createRenderer();
renderer.render(
<HelloComponent />
);
const output = renderer.getRenderOutput();
expect(output.type).toEqual(View);
expect(output.props.children.props.children).toBe("Hello world!");
});
});

View File

@ -0,0 +1,22 @@
import React, { Component } from 'react';
import { Text, View, StyleSheet } from 'react-native';
export default class HelloComponent extends Component {
render() {
return (
<View style={styles.container}>
<Text>Hello world!</Text>
</View>
);
}
}
var styles = StyleSheet.create({
container: {
flex: 1,
flexDirection: 'row',
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'blue'
},
});

View File

@ -7,13 +7,13 @@
"example": "examples"
},
"scripts": {
"test": "mocha --compilers js:babel-core/register",
"test-mocha": "mocha --compilers js:babel-core/register",
"test": "rm -rf ./node_modules/jest-cli/.haste_cache && jest",
"lint": "eslint ."
},
"repository": {
"type": "git",
"url": "git+ssh://git@github.com:instea/react-native-popup-menu.git"
},
"author": "instea.co",
"license": "ISC",
@ -21,15 +21,30 @@
"url": "https://github.com/instea/react-native-popup-menu/issues"
},
"homepage": "https://github.com/instea/react-native-popup-menu",
"jest": {
"scriptPreprocessor": "<rootDir>/node_modules/babel-jest",
"testFileExtensions": [ "js" ],
"moduleFileExtensions": [ "js" ],
"unmockedModulePathPatterns": [
"<rootDir>/node_modules/react",
"<rootDir>/node_modules/fbjs"
],
"verbose": true,
"collectCoverage": true
},
"devDependencies": {
"babel-core": "^6.8.0",
"babel-eslint": "^6.0.4",
"babel-jest": "^12.0.2",
"babel-preset-react": "^6.5.0",
"babel-preset-react-native": "^1.7.0",
"chai": "^3.5.0",
"eslint": "^2.9.0",
"eslint-plugin-react": "^5.1.1",
"jest-cli": "^12.0.2",
"mocha": "^2.4.5",
"react": "^15.0.2",
"react-addons-test-utils": "^15.0.2",
"sinon": "^1.17.4"
}
}