Skip to content

Jest setup

Kenza Boulisfane edited this page Mar 26, 2020 · 1 revision

Getting Started

  1. Install Jest using npm:

npm install --save-dev jest

  1. In the scripts section, add the following to the package.json file

scripts: { ..., "test": "jest" }

  1. In the same file, create a Jest section as follows:

"jest": { "preset": "jest-expo", "setupFilesAfterEnv": [ "<rootDir>setupTests.js" ], "transformIgnorePatterns": [ "node_modules/(?!(jest-)?react-native|unimodules-permissions-interface|react-clone-referenced-element|@react-native-community|expo(nent)?|@expo(nent)?/.*|react-navigation|@react-navigation/.*|@unimodules/.*|sentry-expo|native-base)" ], "collectCoverage": true, "collectCoverageFrom": [ "**/*.{js,jsx}", "!**/coverage/**", "!**/node_modules/**"] }

  1. Add Jest to Travis CI:

language: node_js node_js:

  • node
  • lts/* cache: directories:
    • ~/.npm\
    • .jest before_script:
  • npm install -g npm@latest script:
  • npm ci
  • npx jest --ci
  • npm test -- --coverage --updateSnapshot

Clone this wiki locally