Changing path of files in Jest unit tests

If you want to control where Jest looks for tests, you can simply add a “jest” section to package.json, and set “testPathDirs”. There are a whole bunch of other options in the documentation1

{
  "name": "books",
  "version": "1.0.0",
  "description": "",
  "main": "import-editions.tsx",
  "scripts": {
    "test": "jest"
  },
  "jest": { 
    "testPathDirs": ["dist/__test__/"] 
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "bluebird": "^3.4.1",
    "lodash": "^4.13.1",
    "rethinkdb": "^2.3.2"
  },
  "devDependencies": {
    "jest-cli": "^13.2.3"
  }
}
  1. https://facebook.github.io/jest/docs/api.html#testpathdirs-array-string []

Leave a Reply

Your email address will not be published. Required fields are marked *