react-jest

0.2.1 • Public • Published

react-jest

NPM version NPM downloads CircleCI donate

Inspired by create-react-app but react-jest comes as a standalone module, basically this would work out of the box for projects created by create-react-app and most React projects.

Install

# Recommend 
yarn add react-jest --dev
# Alternative 
# yarn global add react-jest 

Features

  • .js|jsx files are transformed with babel-preset-react-app which is used by create-react-app, you can also use custom .babelrc.
  • Run tests in jsdom enviroment by default.
  • Importing css files would return an empty object, while importing other kinds of file would return the path to it.
  • Support all Jest cli options.
  • Support API usage.

Usage

Let's say that you already wrote some jest tests for your React app, for example src/App.test.js, then configure npm scripts:

{
  "scripts": {
    "test": "react-jest"
  }
}

Then run npm test, and it accepts all jest cli options, for example if you don't need browser environment, use react-jest --env=node.

preview

Which is also worth noting, you can still configure jest field in package.json, react-jest will load it automatically.

API

Besides using as a CLI utility, you can also use the react-jest node.js API.

const runJest = require('react-jest')
 
runJest(options)

options

jestConfig

Type: object function

- object:

Use your custom jest config which will be merged (using lodash.merge) with base jest config.

- function:

Use a function to mutate base jest config:

function mutateJestConfig(config) {
  // Use polyfill before each test
  config.setupFiles = ['./src/polyfills.js']
  return config
}

argv

Type: Array

Addtional CLI arguments for jest cli, like ['--env=node']

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

Author

react-jest © egoist, Released under the MIT License.
Authored and maintained by egoist with help from contributors (list).

egoistian.com · GitHub @egoist · Twitter @rem_rin_rin

Readme

Keywords

none

Package Sidebar

Install

npm i react-jest

Weekly Downloads

16

Version

0.2.1

License

MIT

Last publish

Collaborators

  • rem