Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jest "No tests found, exiting with code 1" error on Windows 10 in React Redux application

Tags:

I am attempting to run Jest on my project. I am on a Windows 10. I only have one test in one test file.

In package.json:

    "test": "jest" 

My directory structure:

    src/         app/             routeName/                 redux/                     action.tests.js 

My output:

No tests found, exiting with code 1 Run with `--passWithNoTests` to exit with code 0 In C:\Users\myUsername\Documents\myApp   47 files checked.   testMatch: **/__tests__/**/*.[jt]s?(x), **/?(*.)+(spec|test).[tj]s?(x) - 0 matches   testPathIgnorePatterns: \\node_modules\\ - 47 matches   testRegex:  - 0 matches Pattern:  - 0 matches npm ERR! Test failed.  See above for more details. 

According to the documentation here, Jest should look for anything that has test.js in the name.

I have also tried tests.js and that didn't work either.

I created a folder in the root of the project and put a test in there as __tests__/tests.js and that did work, but I do not want it placed there.

I have seen several tickets and questions about questions that are superficially similar, but all of those involve more complex configurations, or bugs that were supposedly patched already. I have no special configurations set. The documentation says this should work. Tutorials I have read for Jest include the exact setup I am currently using.

I am using Babel and Webpack. I installed the jest and babel-jest packages. I also added jest to the ESLint environment.

[edit] updated to properly document my problem, which I answered below. I lost track of my file naming.

like image 794
cdpautsch Avatar asked May 28 '19 18:05

cdpautsch


People also ask

How do I run a jest test in terminal?

In order to run a specific test, you'll need to use the jest command. npm test will not work. To access jest directly on the command line, install it via npm i -g jest-cli or yarn global add jest-cli . Then simply run your specific test with jest bar.

Does react scripts test use jest?

Create React App uses Jest as its test runner. To prepare for this integration, we did a major revamp of Jest so if you heard bad things about it years ago, give it another try. Jest is a Node-based runner. This means that the tests always run in a Node environment and not in a real browser.


2 Answers

I am a bloody idiot and I didn't pay attention to the details.

Jest is looking for test.js specifically. Not testS.js. My files were labeled as tests.js. It worked inside __tests__/ because Jest just looks for anything inside there.

I got it working just fine now, and it shall remain up as a testament to me not looking at the specifics of the regex matches.

like image 152
cdpautsch Avatar answered Sep 22 '22 18:09

cdpautsch


I had the same Problem with a React-App. Make sure, that the jest config file has the correct file pattern to find the tests:

// jest.config.js module.exports = {     testMatch: [         '<rootDir>/src/**/*.test.js',         '<rootDir>/src/**/*.test.jsx',     ],     ... } 
like image 38
jzilg Avatar answered Sep 23 '22 18:09

jzilg