How to run Jest tests only for current folder?

Sometimes, we want to run Jest tests only for current folder.

In this article, we’ll look at how to run Jest tests only for current folder.

How to run Jest tests only for current 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.

For instance, we run

npm test dev/app

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.

For instance, we run

jest --watchAll --testPathPattern=dev/app

to run the tests in dev/app.

Conclusion

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.