Set up Jest to be able to test RN UI components (#96)

This commit is contained in:
Ferran Negre
2017-01-31 04:13:24 +01:00
committed by Satyajit Sahoo
parent 123bce5402
commit d0582d205d
4 changed files with 42 additions and 5 deletions

3
.gitignore vendored
View File

@@ -17,3 +17,6 @@ yarn-error.log
# Exponent
.exponent
# Jest
coverage

21
jest-setup.js Normal file
View File

@@ -0,0 +1,21 @@
/* @flow */
// See https://github.com/facebook/jest/issues/2208
jest.mock('Linking', () => {
return {
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
openURL: jest.fn(),
canOpenURL: jest.fn(),
getInitialURL: jest.fn().mockImplementation((value: string) => Promise.resolve(value)),
}
});
// See https://github.com/facebook/react-native/issues/11659
jest.mock('ScrollView', () => {
const RealComponent = require.requireActual('ScrollView');
class ScrollView extends RealComponent {
scrollTo = () => {}
}
return ScrollView
});

View File

@@ -26,7 +26,7 @@
"start": "node ./node_modules/react-native/local-cli/cli.js start --config ./rn-cli.config.js",
"run-playground-ios": "cd examples/NavigationPlayground && react-native run-ios",
"run-playground-android": "cd examples/NavigationPlayground && react-native run-android",
"test": "BABEL_ENV=development jest",
"test": "jest",
"flow": "flow",
"prepublish": "npm run clean && npm run build"
},
@@ -55,7 +55,8 @@
"jest": "^18.1.0",
"react": "~15.4.0",
"react-native": "^0.40.0",
"react-native-vector-icons": "^3.0.0"
"react-native-vector-icons": "^3.0.0",
"react-test-renderer": "^15.4.2"
},
"peerDependencies": {
"react": "*",
@@ -69,9 +70,14 @@
"react-native-tab-view": "^0.0.54"
},
"jest": {
"testPathDirs": [
"src/"
"notify": true,
"preset": "react-native",
"testRegex": "./src/.*\\-test\\.js$",
"setupFiles": [
"<rootDir>/jest-setup.js"
],
"notify": true
"modulePathIgnorePatterns": [
"examples"
]
}
}

View File

@@ -3904,6 +3904,13 @@ react-proxy@^1.1.7:
lodash "^4.6.1"
react-deep-force-update "^1.0.0"
react-test-renderer@^15.4.2:
version "15.4.2"
resolved "https://registry.yarnpkg.com/react-test-renderer/-/react-test-renderer-15.4.2.tgz#27e1dff5d26d0e830f99614c487622bc831416f3"
dependencies:
fbjs "^0.8.4"
object-assign "^4.1.0"
react-timer-mixin@^0.13.2:
version "0.13.3"
resolved "https://modules.verse.link/react-timer-mixin/-/react-timer-mixin-0.13.3.tgz#0da8b9f807ec07dc3e854d082c737c65605b3d22"