How do I run Jest test from specific folder only neglecting other folder test?

Viewed 861

I have a node js project and it have 2 test folders. There are app & admin folder inside of src/test/v1. I want script to run test from only app folder. I tried using jest app, jest app --testPathPattern=src/__test__/v1/app"but both didn't worked.

1 Answers

By default jest will try to run all tests recursively of the root directory (where package.json is)

To specify a specific folder via CLI :

jest --testPathPattern=src/test/v1/app

You can also setup package.json to have specific test commands for running tests for specific folders:

"scripts": {
   "test:app": "jest --testPathPattern=src/test/v1/app",
   "test:admin": "jest --testPathPattern=src/test/v1/admin",
},
Related