Simple testing configuration for React Native with Jest
JavaScript Objective-C Java Shell
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
Example
__tests__
src
.gitignore
.npmignore
.travis.yml
LICENSE
README.md
configure
configure.js
env.js
index.js
package.json
publish
travis

README.md

react-native-babel-jest

Build Status Coverage Status

Simple testing configuration for React Native with Jest

Installation

npm i --save-dev react-native-babel-jest jest-cli

Usage

Add configuration to package.json file

{
  "scripts": {
    "test": "jest"
  },
  ...
  "jest": {
    "scriptPreprocessor": "<rootDir>/node_modules/react-native-babel-jest",
    "setupFiles": [
      "<rootDir>/node_modules/react-native-babel-jest/env.js"
    ],
    "automock": true,
    "unmockedModulePathPatterns": [
      "react",
      "enzyme",
      "promise",
      "source-map"
    ]
  }
}

Write your test in __tests__ folder, run test command

npm test

Recommendation

We recommend you using enzyme to render components, and enzyme-to-json to make snapshot testing. See more in the example below.

Example

See this example