Skip to content

unit tests

Nelson Omuto edited this page Jul 12, 2018 · 3 revisions

To use this repo as an example for getting started and to setup jest in another pocket repo.

screen shot 2018-07-12 at 10 05 42 am

Outcome

The outcome is simple:

  1. Run the app locally
  2. Run npm run test:watch
  3. Write code and unit tests 💥 (for organization purposes and to group snapshots, tests should be either colocated with a corresponding src file or under a __test__ directory and the filename should match **.test.js)
  4. Make sure to include any generated snapshots in your git commit 😅

To read more on the philosophy behind snapshots and jest visit their website.

Setup

To setup jest for other pocket react apps follow these steps: (note this is already done in this repo ✅)

  1. Install the following dependencies (add them to your package.json and run npm i):
    "babel-core": "^6.26.0",
    "babel-eslint": "^7.1.1",
    "babel-jest": "^21.2.0",
    "babel-loader": "^7.1.2",
    "babel-plugin-dynamic-import-node": "^1.0.2",
    "babel-plugin-syntax-dynamic-import": "^6.18.0",
    "babel-plugin-transform-class-properties": "^6.23.0",
    "babel-plugin-transform-decorators-legacy": "^1.3.4",
    "babel-plugin-transform-object-rest-spread": "^6.26.0",
    "babel-plugin-transform-runtime": "^6.23.0",
    "babel-preset-env": "^1.6.0",
    "babel-preset-flow": "^6.23.0",
    "babel-preset-react": "^6.23.0",
    "react": "^16.0.0",
    "react-dom": "^16.0.0",
    "react-hot-loader": "^3.0.0-beta.7",
    "react-redux": "5.0.6",
    "react-router": "^4.2.0",
    "react-router-dom": "^4.2.0",
    "react-test-renderer": "^16.0.0",
  1. Update your circle config.yml file to run jest tests
screen shot 2018-07-12 at 9 48 12 am
  1. Add a .babelrc to the root of your repo

  2. Add the following jest plugins by copying .tooling/config/jest

  3. Update your package.json scripts with the test alias

  4. Update or add to your package.json to the following precommit config