Massimiliano Kraus
Massimiliano Kraus

Reputation: 3835

How to see matched files in the pattern matching option of a Jest execution?

When I execute tests with Jest, you have these options:

enter image description here

If I'm in a React app created with create-react-app, I run the test, I use the p options, and I digit the pattern, the list of matched files is shown:

enter image description here

Instead, when I run Jest in a custom app I created (adding Jest manually), the matched files are not shown:

enter image description here

How can I see the matched files in Jest like create-react-app does?

This is my current package.json's Jest section:

"jest": {
    "moduleDirectories": [
        "node_modules",
        "."
    ]
}

Upvotes: 1

Views: 916

Answers (1)

Massimiliano Kraus
Massimiliano Kraus

Reputation: 3835

Add the jest-watch-typeahead package to the project, and then add this part to the package.json's Jest section:

"jest": {
    "watchPlugins": [
        "jest-watch-typeahead/filename",
        "jest-watch-typeahead/testname"
    ]
}

(This is exactly what create-react-app is doing, and you can see this by ejecting the project with yarn eject).

If you're using a jest.config.js file, the package.json configuration will be ignored. Forget the package.json and add this property to the main exported object of the jest.config.js file:

watchPlugins: [
    "jest-watch-typeahead/filename",
    "jest-watch-typeahead/testname"
]

Upvotes: 2

Related Questions