How do I move jest tests to a /test folder and get them to run?

I think the best way to go about this is to configure testMatch. It defaults to:

[ "**/__tests__/**/*.[jt]s?(x)", "**/?(*.)+(spec|test).[jt]s?(x)" ]

So you could either change __tests__ to tests or add a new entry into the array that checks for both. My use the following in my package.json:

  "jest": {
    "testMatch": [ "**/tests/**/*.[jt]s?(x)", "**/?(*.)+(spec|test).[jt]s?(x)" ]
  },

I think to set roots: ['<rootDir>/test/'] is simple way in jest.config.js

module.exports = {
 roots: ['<rootDir>/test_unit/'],
 ...
}

It works well for me.


I solved the problem by just setting the regex so it finds all .js files in my ./test folder:

"jest": {
   "preset": "react-native",
    "globals": {
        "__DEV__": true
    },
    "testRegex": "./test/.*.js$",
    "rootDir": "."
 },

(jcollum here: I don't know what __DEV__ is actually doing there but an error will be thrown if isn't. jest 17.0.3)