Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specify jest test files directory

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

like image 379
Geoff Avatar asked Oct 03 '18 23:10

Geoff


People also ask

Where are Jest test files stored?

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.

How do I run a Jest test for a specific file?

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.

How do I run a Jest file in a folder?

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 .


2 Answers

Add the directory name as an argument

scripts:{     "test": "jest --verbose ./my-directory" } 
like image 165
FuzzyTree Avatar answered Sep 22 '22 12:09

FuzzyTree


Add configuration to your package.json.

"jest": {   "testMatch": ["**/laratest/**/*.test.js"] } 

https://jestjs.io/docs/en/configuration.html#testmatch-arraystring

like image 35
CodeDraken Avatar answered Sep 25 '22 12:09

CodeDraken