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.
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.
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.
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.
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', ], ... }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With