apentle / react-native-babel-jest

Simple testing configuration for React Native with Jest

Home Page:http://blog.apentle.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

About

Simple testing configuration for React Native with Jest

http://blog.apentle.com/

License:MIT License


Languages

Language:JavaScript 52.2%Language:Objective-C 35.1%Language:Java 7.1%Language:Shell 5.5%