Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jest tests broken after implementing detox

I'd like to be able to run my detox tests and my Jest unit tests separately. For example, run detox tests with detox build && detox test, and my Jest unit tests with npm test.

After implementing detox (using mocha as the test runner), running npm test results in immediate error, and looks like its trying to run my detox tests (not what I'd expect)! Here's the first error I get.

FAIL e2e/auth.spec.js

Not sure why its trying to run detox tests, when my package.json is pointing the test script to Jest. "scripts": { "start": "node node_modules/react-native/local-cli/cli.js start", "test": "jest" }

How do I run my jest tests now?

like image 771
Mark Newton Avatar asked Mar 14 '18 21:03

Mark Newton


2 Answers

By default jest runs all files in your project directory, that have the .test. or .spec. extension to them. That's why it picks up your detox test files and fails to execute them.

https://facebook.github.io/jest/docs/en/configuration.html#testmatch-array-string

You have to override this default behavior in order for the two not to clash. Here's what we use in our package.json just for reference, you might want to change it:

"jest": {
  "testMatch": [
    "<rootDir>/__tests__/**/*.test.js?(x)",
    "<rootDir>/src/**/*.test.js"
  ]
}
like image 134
joncys Avatar answered Oct 08 '22 08:10

joncys


If you dont keep you files in on folder like tests just add this to package.json

"jest": {
   "testMatch": ["**/*+(.test.js)"] 
}
like image 30
Yestay Muratov Avatar answered Oct 08 '22 07:10

Yestay Muratov