Am new to unit testing and i wanted only to test files located in a specific directory only
How do i specify that i want tests to run to files only on a specific directory and ignore others
so i have installed jest via npm
"jest": "^23.6.0",
And specified my test command in package.json via
scripts:{ "test": "jest --verbose" }
The above runs all the files but i want it to run for files in a specific directory eg laratest directory only
How do i proceed
Where to put test files. Unit tests run against specific lines of code. So it makes sense to place them right next to that code. Integration tests run against many lines of code in many files.
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.
To run Jest tests only for current folder, we can run jest with the path of the folder with the tests we want to run. to run the tests in the dev/app folder given that the test script runs jest . We can also set the testPathPattern option to the folder with the tests we want to run. to run the tests in dev/app .
Add the directory name as an argument
scripts:{ "test": "jest --verbose ./my-directory" }
Add configuration to your package.json.
"jest": { "testMatch": ["**/laratest/**/*.test.js"] }
https://jestjs.io/docs/en/configuration.html#testmatch-arraystring
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