If you want to restrict Jest testing to a specific directory and specify the type of files to be read (for example: 'ExampleComponent.test.js' with Jest version @24.9.0), you need to define the exact "testMatch" in your jest.config.json or package.json under the "jest" section like this
"testMatch": [ "<rootDir>/src/__tests/**/*.test.js" ]
.
In my scenario, this testMatch pattern targets all files starting with .test.js in
tests subdirectories while ignoring other files like 'setupTest.js' and other .js files in the '
mocks' subdirectory located within the '
tests' directory, hence my 'jest.config.json' appears as follows
{
"setupFiles": [
"raf/polyfill",
"<rootDir>/setupTests.js"
],
"snapshotSerializers": [
"enzyme-to-json/serializer"
],
"moduleNameMapper": {
"^.+\\.(css|less|scss|sass)$": "identity-obj-proxy"
},
"testMatch": [
"<rootDir>/src/__tests/**/*.test.js"
]
}
You can adjust the regular expression used for 'testMatch' according to your requirements.
Just a side note: This is applicable for [email protected] && [email protected] if it's relevant to anyone.
I trust that this information will prove helpful to someone, best wishes to all.