Skip to content

Commit

Permalink
Update for React Native 0.28.0+
Browse files Browse the repository at this point in the history
  • Loading branch information
doanndd committed Jul 11, 2016
1 parent 9551bf5 commit 627824f
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 25 deletions.
6 changes: 3 additions & 3 deletions Example/package.json
Expand Up @@ -7,13 +7,13 @@
"test": "jest"
},
"dependencies": {
"react": "^0.14.7",
"react-native": "^0.22.2"
"react": "^15.2.0",
"react-native": "^0.28.0"
},
"devDependencies": {
"enzyme": "^2.2.0",
"babel-preset-airbnb": "2.0.0",
"react-dom": "0.14.7",
"react-dom": "^15.2.1",
"react-native-babel-jest": "^0.x"
},
"jest": {
Expand Down
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -5,12 +5,12 @@ Simple testing configuration for React Native with Jest

## Installation
```bash
npm i --save-dev react-native-babel-jest
npm i --save-dev react-native-babel-jest jest-cli
```

## Usage
Add configuration to `package.json` file
```bash
```javascript
{
"scripts": {
"test": "jest"
Expand Down
14 changes: 10 additions & 4 deletions env.js
@@ -1,9 +1,15 @@
'use strict';

/**
* Import react native env.js
*/
require('react-native/jestSupport/env.js');
require.requireActual('react-native/packager/react-packager/src/Resolver/polyfills/babelHelpers.js');

global.__DEV__ = true;
global.__fbBatchedBridgeConfig = {
remoteModuleConfig: [],
localModulesConfig: [],
};

global.Promise = require('promise');
global.regeneratorRuntime = require.requireActual('regenerator-runtime/runtime');

/**
* Mock react-native
Expand Down
10 changes: 6 additions & 4 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "react-native-babel-jest",
"version": "0.0.5",
"version": "0.1.0",
"description": "Simple testing configuration for React Native with Jest",
"main": "index.js",
"scripts": {
Expand All @@ -26,17 +26,19 @@
},
"homepage": "https://github.com/apentle/react-native-babel-jest#readme",
"dependencies": {
"babel-core": "^6.0.0",
"babel-core": "^6.10.4",
"babel-preset-react-native": "^1.9.0",
"jest-cli": "^11.0.2"
"promise": "^7.1.1",
"regenerator-runtime": "^0.9.5"
},
"peerDependencies": {
"react": "*",
"react-native": "*"
},
"devDependencies": {
"jest-cli": "^13.2.3",
"jsonfile": "^2.3.0",
"react-native-mock": "^0.0.7"
"react-native-mock": "^0.2.4"
},
"jest": {
"scriptPreprocessor": "<rootDir>/index.js",
Expand Down
14 changes: 4 additions & 10 deletions react-native.js
Expand Up @@ -14,20 +14,21 @@ const renderToHTML = (type) => {
if (typeof proto !== 'undefined') {
const render = function () {
var properties = {className: type};
Object.assign(properties, this.props);
/**
* use onClick for Simulate instead of onPress
*/
if (typeof this.props.onPress !== 'undefined') {
properties.onClick = this.props.onPress;
delete properties.onPress;
}
// TODO: add more event mapping
Object.assign(properties, this.props);
return (
<div {...properties}>{this.props.children}</div>
);
};
proto.__reactAutoBindMap['render'] = render;
proto.render = render;
//proto.__reactAutoBindPairs[proto.__reactAutoBindPairs.indexOf['render'] + 1] = render;
proto['render'] = render;
}
};

Expand Down Expand Up @@ -76,11 +77,4 @@ const renderToHTML = (type) => {
'WebView',
].forEach(renderToHTML);

/**
* ListView mock for react native
*/
ReactNative.ListView.defaultProps = {
renderScrollComponent: props => <ReactNative.ScrollView {...props} />,
};

module.exports = ReactNative;
3 changes: 1 addition & 2 deletions travis
Expand Up @@ -13,8 +13,7 @@ cd ..
else

# run before install in travis-ci
sed -i 's/"jest-cli"/"react": "^0.14.7","react-native": "^0.22.2","jest-cli"/g' package.json

npm install react react-native
npm install --only=dev
node configure.js

Expand Down

0 comments on commit 627824f

Please sign in to comment.