running docker mhart/alpine-node:8 on macOS with
nodejs (6.10.3-r0) (18/18) yarn 0.24.6 jest 20.0.4
I have a __tests__/index.test.js file however, when running the code
node_modules/.bin/jest --watchAll
I get the below output
No tests found
In /usr/src/app
5 files checked.
testMatch: /__tests__/ /*.js?(x),**/?(*.)(spec|test).js?(x) - 1 match
testPathIgnorePatterns: /node_modules/,/src, src - 0 matches
Pattern: "" - 0 matches
I've re-installed the package numbers times but to no avail.
Your output says that testMatch
had 1 match
, which may be your __tests__/index.test.js
file. It seems that your testPathIgnorePatterns
is causing that test suite to be ignored. No tests found In /usr/src/app
says that Jest is looking for tests in /usr/src/app
, and testPathIgnorePatterns: /node_modules/,/src,src
says that Jest is ignoring files in /src
directories.
Either point Jest to look at the location of your __tests__/index.test.js
file if it is outside the /src directory, or stop testPathIgnorePatterns
from ignoring the /src directory.
If you have file structure such as the following
myFolder
│ myFile1.js
│ myFile2.js
│ ...
│
└───__tests__
myFile1.spec.js
myFile2.spec.js
...
then you need to have in jest.config.js
the following pattern for testMatch
property:
testMatch: ['**/__tests__/*.js?(x)'],
The simple example of jest.config.js
:
const jestConfig = {
verbose: true,
testURL: "http://localhost/",
'transform': {
'^.+\\.jsx?$': 'babel-jest',
},
testMatch: ['**/__tests__/*.js?(x)'],
}
module.exports = jestConfig
如果你想运行测试文件夹中的所有测试,你可以简单地执行以下jest __tests__ --watch
You can try running jest
without any parameters. A key thing to note is the test file names have to follow the convention *.test.js
or *.spec.js
.
In package.json there is a pattern that is used to find test file. In this pattern, you can change it according to your file location or make it the global pattern.
I wrote a test, not in the specific folder and follow a naming convention *.test.js
and change testMatch
"testMatch": [
"<rootDir>/src/**/*.(test).{js,jsx,ts,tsx}",
"<rootDir>/src/**/?(*.)(spec|test).{js,jsx,ts,tsx}"
],
Moving the __tests__
filter into src
fixed the issue for me. Now its able to run the tests.
I had this error while attempting to run tests in a submodule of a project. Fixed the issue by testing the submodule in isolation, in a separate folder tree from the main project.
If you're using Typescript, I started getting the same No tests found
error after I updated Typescript to 3.8.3 from 3.3. Updating jest and ts-jest from version 23.* to 25.* fixed it for me.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.