close

How can I exclude files from Jest watch?

Hello Guys, How are you all? Hope You all Are Fine. Today we are going to learn How can I exclude files from Jest watch? in javascript. So Here I am Explain to you all the possible methods here.

Without wasting your time, Let’s start This Article.

How can I exclude files from Jest watch ?

  1. How can I exclude files from Jest watch ?

    can I exclude files from Jest watch Based on Jest documentation, watchPathIgnorePatterns should be the way you want to go. That works in Jest 23.x.x and later.
    You can add this config to jest.config.js or package.json > jest

  2. How can I exclude files from Jest watch ?

    can I exclude files from Jest watch Based on Jest documentation, watchPathIgnorePatterns should be the way you want to go. That works in Jest 23.x.x and later.
    You can add this config to jest.config.js or package.json > jest

Method 1

To exclude a directory from Jest testing, use testPathIgnorePatterns

testPathIgnorePatterns

"testPathIgnorePatterns": ["directory to ignore"]

Below in file package.json, I have configured to ignore the “src” directory

{
      "name": "learn-test",
      "jest": {
        "testPathIgnorePatterns": ["src"]
      },
      "version": "0.1.0",
      "private": true,
      "dependencies": {
        "react": "^16.4.1",
        "react-dom": "^16.4.1",
        "react-scripts": "1.1.4"
      },
      "scripts": {
        "start": "react-scripts start",
        "build": "react-scripts build",
        "test": "jest --watch",
        "eject": "react-scripts eject",

      },

      "devDependencies": {}
    }

Method 2

Based on Jest documentation, watchPathIgnorePatterns should be the way you want to go. That works in Jest 23.x.x and later.

You can add this config to jest.config.js or package.json > jest

Summery

It’s all About this article. Hope all method helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which method worked for you? Thank You.

Leave a Comment