# Jest

> **TL;DR**
> Required plugin:
>
>
>
> `JavaScript and TypeScript` -    the plugin is bundled with IntelliJ IDEA and enabled by default.

Jest is a testing platform for client-side JavaScript applications and [React](https://facebook.github.io/react/) applications specifically. Learn more about the platform from the [Jest](https://facebook.github.io/jest/) official website.

You can run and debug tests with Jest right in IntelliJ IDEA. You can see the test results in a treeview and easily navigate to the test source from there. Test status is shown next to the test in the editor with an option to quickly run it or debug it.

## Before you start

Procedure:

1. Download and install [Node.js](http://nodejs.org/#download).

2. Make sure the  JavaScript and TypeScript plugin is enabled in the settings.  Press `Ctrl+Alt+S` (Windows), `⌘ Comma` (macOS), `⌘ Comma` (IntelliJ IDEA Classic (macOS)), `⌘ Comma` (macOS System Shortcuts), `Ctrl+Alt+S` (XWin), `Ctrl+Alt+S` (GNOME), `Ctrl+Alt+S` (KDE), `Ctrl+Alt+S` (Emacs), `Ctrl+Alt+S` (Sublime Text), `⌘ Comma` (Sublime Text (macOS)), `Ctrl+Alt+S` (NetBeans), `Ctrl+Alt+S` (Visual Studio), `⌘ Comma` (Visual Studio (macOS)), `Ctrl+Alt+S` (Eclipse), `⌘ Comma` (Eclipse (macOS)) to open settings and then select `Plugins`.  Click the Installed tab. In the search field, type JavaScript and TypeScript. For more information about plugins, refer to [Managing plugins](managing-plugins.html).

## Install and configure Jest

Procedure:

* In your command-line shell or in the embedded Terminal (`Alt+F12` (Windows), `⌥ F12` (macOS), `⌥ F12` (IntelliJ IDEA Classic (macOS)), `⌘ ⌃ T` (macOS System Shortcuts), `Alt+F12` (XWin), `Alt+F12` (GNOME), `Alt+F12` (KDE), `Alt+F12` (Emacs), `Alt+F12` (Sublime Text), `⌥ F12` (Sublime Text (macOS)), `Alt+F12` (NetBeans), `Ctrl+Alt+1` (Visual Studio), `⌘ ⌃ 1` (Visual Studio (macOS)), `Alt+F12` (Eclipse), `⌥ F12` (Eclipse (macOS))) , type:

`npm install --save-dev jest`

Learn more from [Getting Started](https://jestjs.io/docs/en/getting-started) and [Configuring Jest](https://jestjs.io/docs/en/configuration) on the Jest official website.

## Run tests

With IntelliJ IDEA, you can quickly run a single Jest test right from the editor or create a run/debug configuration to execute some or all of your tests.

For more information about creating Vitest tests for JavaScript and TypeScript code, refer to [Vitest features](https://vitest.dev/guide/features.html) on the Vitest official website.

Procedure: Run a single test from the editor

* Click ![the Run icon](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app-client.expui.run.run.svg) or ![the Rerun icon](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.actions.rerun.svg) in the gutter and select Run <test_name> from the list.

![Run single test from the editor](https://resources.jetbrains.com.cn/help/img/idea/2026.2/ws_run_test_from_editor_600.animated.gif)  You can also see whether a test has passed or failed right in the editor, thanks to the test status  icons ![Test passed](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.runConfigurations.testState.green2.svg) and ![Test failed](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.runConfigurations.testState.red2.svg) in the gutter.

Procedure: Run all tests in a folder from the Project tool window

* In the   Project tool window  (`Alt+1` (Windows), `⌘ 1` (macOS), `⌘ 1` (IntelliJ IDEA Classic (macOS)), `⌘ 1` (macOS System Shortcuts), `Alt+1` (XWin), `Alt+1` (GNOME), `Alt+1` (KDE), `Alt+1` (Emacs), `Alt+1` (Sublime Text), `⌘ 1` (Sublime Text (macOS)), `Ctrl+1` (NetBeans), `Ctrl+Alt+L` (Visual Studio), `⌘ ⌥ L` (Visual Studio (macOS)), `Alt+1` (Eclipse), `Alt+1` (Eclipse (macOS))) , select the folder with the tests, and then select Run 'Tests in <folder name>'.

![Run all tests in a folder](https://resources.jetbrains.com.cn/help/img/idea/2026.2/ws_jest_run_tests_from_folder.png)

Procedure: Create a Jest run configuration

1. Open the [Run/Debug Configuration](run-debug-configurations-dialog.html) dialog (`Run | Edit Configurations` in the main menu), click ![the Add button](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.expui.general.add.svg) in the left-hand pane, and select Jest from the list.  The [Run/Debug Configuration: Jest](run-debug-configuration-jest.html) dialog opens.

> **Tip:**
> Alternatively,   select a test file in the   Project tool window  (`Alt+1` (Windows), `⌘ 1` (macOS), `⌘ 1` (IntelliJ IDEA Classic (macOS)), `⌘ 1` (macOS System Shortcuts), `Alt+1` (XWin), `Alt+1` (GNOME), `Alt+1` (KDE), `Alt+1` (Emacs), `Alt+1` (Sublime Text), `⌘ 1` (Sublime Text (macOS)), `Ctrl+1` (NetBeans), `Ctrl+Alt+L` (Visual Studio), `⌘ ⌥ L` (Visual Studio (macOS)), `Alt+1` (Eclipse), `Alt+1` (Eclipse (macOS)))  and select Create <filename> from the context menu.

2. Specify the Node.js runtime to use.

If you choose the Project alias, IntelliJ IDEA will automatically use the project default interpreter from the Node runtime field on the [JavaScript Runtime](javascript-runtime.html) page . In most cases, IntelliJ IDEA detects the project default runtime and fills in the field itself.

You can also choose another configured local or remote interpreter or click ![the Browse button](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.general.ellipsis.svg) and configure a new one.

3. Specify the location of the  jest, react-scripts, react-script-ts, react-super-scripts, or react-awesome-scripts  package.

4. Specify the  working directory of the application. By default, the Working directory field shows the project root folder. To change this predefined setting, specify the path to the desired folder.

5. Specify the tests to run. This can be a specific test or suite, an entire test file, or a folder with test files.

6. Optionally:

Specifyy the `jest.config.js` or `jest.config.ts` file to use: select the relevant file from the list, or click ![the Browse button](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.general.ellipsis.svg) and select it in the dialog that opens, or just type the path in the field.

If the field is empty, IntelliJ IDEA looks for a `package.json` file with a `jest` key. The search is performed in the file system upwards from the working directory. If no appropriate `package.json` file is found, then a [Jest default configuration](https://facebook.github.io/jest/docs/en/configuration.html#options) is generated on the fly.

7. Optionally:

Configure rerunning tests automatically on changes in the related source files. To do that, add the `--watch` flag in the Jest options field.

You can also turn the [watch](https://jestjs.io/docs/cli#--watch) mode on later by pressing the Watch for Changes toggle button in the Run tool window during a test session, refer to [Rerun
test automatically on changes (watch mode)](#ws_js_test_rerun_tests_on_changes) below.

8. Optionally:

Specify the environment variables for executing commands. IntelliJ IDEA will show these variables in completion lists for `process.env`.

![Completion for environment variables from Jest run configuration](https://resources.jetbrains.com.cn/help/img/idea/2026.2/ws_js-jest_test_rc_env_var_completion.png)

9. In the Node options field, optionally type the Node.js-specific command-line options to be passed to the Node.js executable file. The acceptable options are:

* Use `--require coffeescript/register` to have CoffeeScript files compiled into JavaScript on the fly during run. This mode requires that the `register.js` file, which is a part of the `coffeescript` package, is located inside your project. Therefore, make sure you have the `coffeescript` package installed locally as described in [Install the CoffeeScript compiler](coffeescript.html#ws_coffee_installation).

* Use `--inspect` or `--inspect-brk` parameter for [Chrome Debugging Protocol](https://developer.chrome.com/devtools/docs/debugger-protocol) support.

* To use [ECMAScript Modules](https://jestjs.io/docs/ecmascript-modules) in your project, add the `—experimental-vm-modules` flag to the Node options field.

Procedure: Run tests via a run configuration

1. Select the Jest run/debug configuration from the list of configurations and click ![the Run icon](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.expui.run.run.svg) in the list or on the toolbar.

2. Monitor test execution and analyze test results in the Test Runner tab of the Run tool window. For more information, refer to [Explore test results](viewing-and-exploring-test-results.html).

Procedure: Rerun failed tests

* Click ![the Rerun Failed Tests icon](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app-client.expui.run.restartFailedTests.svg) on the test results toolbar. IntelliJ IDEA will execute all the tests that failed during the previous session.

* To rerun a specific failed test, select `Run <test name>` on its context menu.

Procedure: Rerun tests automatically on changes (watch mode)

IntelliJ IDEA supports the [watch](https://jestjs.io/docs/cli#--watch) mode in which a test is rerun automatically as soon as any changes are made to the test-related source file. As a result, you can just make changes to your code without having to rerun tests manually or restart the Jest run/debug configuration.

* In the [Test Runner tab](null), press the Watch for Changes toggle button.

![Turn on the Watch Changes mode](https://resources.jetbrains.com.cn/help/img/idea/2026.2/ws_jest_watch_mode.animated.gif)

* Alternatively, add the `--watch` flag in the Jest options field of the run/debug configuration, refer to [Create a Jest run
configuration](#ws_js_test_rc_jest_options) above.

## Navigation

With IntelliJ IDEA, you can jump between a file and the related test file or from a test result in the [Test Runner Tab](null) to the test.

With IntelliJ IDEA, you can jump between a file and the related test file and between a test or suite definition and its result in the [Test Runner Tab](null).

> **Tip:**
> Such navigation works only if the test file follows popular naming conventions, for example, has a `.test.`, `.spec.`, or `_spec.` suffix and is located either next to the source file or in a `test` folder.

Procedure:

* To jump between a test and its subject or vice versa, open the file in the editor and select `Go to | Test` or `Go to | Test Subject` from the context menu, or just press `Ctrl+Shift+T` (Windows), `⌘ ⇧ T` (macOS), `⌘ ⇧ T` (IntelliJ IDEA Classic (macOS)), `⌃ ⇧ T` (macOS System Shortcuts), `Ctrl+Shift+T` (XWin), `Ctrl+Shift+T` (GNOME), `Ctrl+Shift+T` (KDE), `Ctrl+Shift+T` (Emacs), `Ctrl+Shift+T` (Sublime Text), `Ctrl+Shift+T` (Sublime Text (macOS)), `Ctrl+Shift+T` (NetBeans), `Ctrl+Shift+T` (Visual Studio), `Ctrl+Shift+T` (Visual Studio (macOS)), `Ctrl+Shift+T` (Eclipse), `Ctrl+Shift+T` (Eclipse (macOS)).

* To jump from a test result to the test definition, click the test name in the Test Runner tab twice, or select `Jump to Source` from the context menu, or just press `F4` (Windows), `⌘ ↓` (macOS), `F4` (IntelliJ IDEA Classic (macOS)), `F4` (macOS System Shortcuts), `F4` (XWin), `F4` (GNOME), `F4` (KDE), `F4` (Emacs), `F4` (Sublime Text), `F4` (Sublime Text (macOS)), `F4` (NetBeans), `F4` (Visual Studio), `⌘ ↓` (Visual Studio (macOS)), `F12` (Eclipse), `F3` (Eclipse (macOS)). The test file opens in the editor with the caret placed at the test definition.

* To jump from a test or suite definition to its result in the Test Runner tab, click ![the Test passed icon](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.runConfigurations.testState.green2.svg) or ![the Test failed icon](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.runConfigurations.testState.red2.svg) in the gutter and choose Select <test_name> in Test Tree from the list.

![Jump from test definition to the Test Tree](https://resources.jetbrains.com.cn/help/img/idea/2026.2/ws_jest_jump_to_test_tree.animated.gif)

* For failed tests, IntelliJ IDEA brings you to the failure line in the test from the stack trace. If the exact line is not in the stack trace, you will be taken to the test definition.

![Jump to the failure line from a failed Jest test](https://resources.jetbrains.com.cn/help/img/idea/2026.2/ws_jest_jump_to_failure.animated.gif)

## Snapshot testing

IntelliJ IDEA integration with Jest supports such a great feature as snapshot testing.

When you run a test with a `.toMatchSnapshot()` method, Jest creates a snapshot file in the `__snapshots__` folder. To jump from a test to its related snapshot, click                     ![the Go to snapshot (camera) icon](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.actions.dump.svg) in the gutter next to the test or select the required snapshot from the context menu of the  `.toMatchSnapshot()` method.

![Jest snapshot testing: jump from a test file to the corresponding snapshot](https://resources.jetbrains.com.cn/help/img/idea/2026.2/ws_go_to_jest_snapshhot.png)

If a snapshot does not match the rendered application, the test fails. This indicates that either some changes in your code have caused this mismatch or the snapshot is outdated and needs to be updated.

To see what caused this mismatch, open the IntelliJ IDEA built-in [Diff
Viewer](differences-viewer.html) via the Click to see difference link in the right-hand pane of the Test Runner  tab.

![Jest snapshots: compare the expected and actual snapshots in the IntelliJ IDEA Diff Viewer](https://resources.jetbrains.com.cn/help/img/idea/2026.2/ws_jest_diff_view.animated.gif)

You can update outdated snapshots right from the Test Runner tab of the  Run tool window.

* To update the snapshot for a specific test, use the Click to update snapshot link next to the test name.

* To update all outdated snapshots for the tests from a file, use the Click to update failed snapshots next to the test filename.

![Jest snapshot testing: update snapshots](https://resources.jetbrains.com.cn/help/img/idea/2026.2/ws_jest_update_snapshot.png)

## Debug tests

With IntelliJ IDEA, you can quickly start debugging a single Jest test right from the editor or create a run/debug configuration to debug some or all of your tests.

Procedure:

* [Set the breakpoints](using-breakpoints.html) where necessary.

* To start debugging a single test from the editor, click ![the Run button](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app-client.expui.run.run.svg) or ![the Rerun icon](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.actions.rerun.svg) in the gutter and select Debug <test_name> from the list.

* To start debugging all tests in a folder, select the folder in the Project tool window, and then select Debug 'Tests in <folder name>' from the context menu.

![Debug all tests in a folder](https://resources.jetbrains.com.cn/help/img/idea/2026.2/ws_jest_debug_all_tests_in_folder.png)

* To launch test debugging via a run/debug configuration, create a Jest run/debug configuration [as described above](#createRunConfigJest).

Then select the Jest run/debug configuration from the list of configurations and click ![the Debug icon](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.expui.run.debug.svg) in the list or on the toolbar.

In the [Debug tool window](debug-tool-window.html) that opens,   proceed as usual: [step through the program](stepping-through-the-program.html),  [stop
and resume](starting-the-debugger-session.html#pause-resume)  program execution, [examine it when suspended](examining-suspended-program.html), explore the call stack and variables, set watches, evaluate variables, [view actual HTML DOM](viewing-actual-html-dom.html), and so on.

To ignore source maps and step through the actually executed code, press ![the Disable Source Maps toggle button](https://resources.jetbrains.com.cn/help/img/idea/2026.2/sourceMapDisable.png) on the toolbar of the Debug tool window.

## Monitor code coverage

With IntelliJ IDEA,    you can also monitor how much of your code is [covered with Jest tests](http://en.wikipedia.org/wiki/Code_coverage). IntelliJ IDEA displays this statistics in a dedicated Coverage tool window and marks covered and uncovered lines visually in the editor and in the   Project tool window  (`Alt+1` (Windows), `⌘ 1` (macOS), `⌘ 1` (IntelliJ IDEA Classic (macOS)), `⌘ 1` (macOS System Shortcuts), `Alt+1` (XWin), `Alt+1` (GNOME), `Alt+1` (KDE), `Alt+1` (Emacs), `Alt+1` (Sublime Text), `⌘ 1` (Sublime Text (macOS)), `Ctrl+1` (NetBeans), `Ctrl+Alt+L` (Visual Studio), `⌘ ⌥ L` (Visual Studio (macOS)), `Alt+1` (Eclipse), `Alt+1` (Eclipse (macOS))) .

Procedure: Run tests with coverage

1. Create a Jest run/debug configuration [as described above](#createRunConfigJest).

2. Select the Jest run/debug configuration from the list on the main toolbar and click ![Run with Coverage icon](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.general.runWithCoverage.svg)  to the right of the list.

Alternatively, quickly run a specific suite or a test with coverage from the editor: click ![the Run button](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app-client.expui.run.run.svg) or ![the Rerun button](https://resources.jetbrains.com.cn/help/img/idea/2026.2/app.actions.rerun.svg) in the gutter and select Run <test_name> with Coverage from the list.

![Run Jest tests with coverage from the editor](https://resources.jetbrains.com.cn/help/img/idea/2026.2/ws_jest_quickly-run-with-coverage.png)

3. Monitor the code coverage in the [Coverage](code-coverage.html) tool window. The report shows how many files were covered with tests and the percentage of covered lines in them. From the report you can jump to the file and see what lines were covered – marked green – and what lines were not covered – marked red.

![Jest Coverage report](https://resources.jetbrains.com.cn/help/img/idea/2026.2/ws_jest_coverage_report.png)

## Run Jest tests with Node.js inside a Docker container

With IntelliJ IDEA, you can run [Jest](https://jestjs.io/) tests inside a Docker container just in the same way as you do it locally.

Procedure: Before you start

1. Install and enable the Node.js Remote Interpreter plugin on the Settings | Plugins page, tab Marketplace, as described in [Installing plugins from
JetBrains Marketplace](managing-plugins.html#install_plugin_from_repo).

2. Make sure the Node.js and Docker required plugins are enabled on the Settings | Plugins page, tab Installed. For more information, refer to [Managing plugins](managing-plugins.html).

3. Download, install, and configure Docker as described in [Docker](docker.html).

4. [Configure a Node.js remote
runtime in Docker](node-with-docker.html#ws_node_docker_configure_interpreter) or via [Docker Compose](node-with-docker-compose.html#ws_node_docker_compose_configure_interpreter) and [set it as default](node-with-docker.html#ws_node_docker_manage_dependencies) in your project. Also make sure the package manager associated with this remote runtime is [set as project default](node-with-docker.html#ws_node_docker_manage_dependencies).

5. Open your `package.json` and make sure Jest is listed in the `devDependencies` section:

```JSON
{
    "name": "node-express",
    "version": "0.0.0",
    "private": true,
    "dependencies": {
        "cookie-parser": "~1.4.4",
        "debug": "~2.6.9",
        "express": "~4.16.1",
        "http-errors": "~1.6.3",
        "morgan": "~1.9.1",
        "pug": "^3.0.2"
    },
    "devDependencies": {
        "eslint": "^8.1.0",
        "http-server": "^14.0.0",
        "jest": "^27.3.1"
    }
}
```

6. Right-click anywhere in the editor and select Run '<package manager> install' from the context menu.

Procedure: Run tests

1. Create tests according to the instructions from the [Jest
official website](https://jestjs.io/).

2. Mark the folder where the unit tests are stored as a test source folder, see [Content roots](content-roots.html).

3. Proceed as with local development: run and debug single tests right from the editor or create a run/debug configuration to launch some or all of your tests as described in [Run tests](#ws_jest_running_tests) and [Debug
tests](#ws_jest_debugging_tests) above.

## See also

### Reference

[Run/Debug Configuration: Jest](run-debug-configuration-jest.html)

