On this page:
- Before you start
- Installing Jest
- Quick test launch
- Creating a Jest run/debug configuration
- Launching tests via a run/debug configuration
Before you start
- Make sure the Node.js runtime environment is installed on your computer.
- Make sure the NodeJS plugin is enabled. The plugin is bundled with WebStorm and activated by default. If the plugin is not activated, enable it on the Plugins page of the Settings / Preferences Dialog as described in Enabling and Disabling Plugins.
Open the built-in WebStorm Terminal (press Alt+F12 or choose on the main menu) and type
npm install --save-dev jest at the command line prompt.
You can also install the
jest package on the Node.js and NPM page of the Settings dialog box as described in Node Package Manager (npm). See also Getting Started on the Jest official website.
Quick test launch
You can run and debug Jest tests and suites right from the editor: click or in the left gutter and choose Run <test_file_name> or Debug <test_file_name> from the pop-up list. You can also see whether a test has passed or failed right in the editor, thanks to the test status icons in the left gutter.
Creating a Jest run/debug configuration
- Open the Run/Debug Configuration dialog box by doing one of the following:
- On the main menu, choose .
- Open the test file in the editor, and then choose Create <file name> on the context menu.
- Select the test file in the Project tool window, and then choose Create <file name> on the context menu of the selection.
Click the Add button on the toolbar and select the Jest configuration type. The Run/Debug Configuration: Jest dialog box opens.
- Specify the Node interpreter to use, the location of the jest package, and the working directory of the application. All references in test scripts will be resolved relative to this folder, unless such references use full paths.
By default, the field shows the project root folder. To change this predefined setting, choose the desired folder from the drop-down list, or type the path manually, or click the Browse button and select the location in the dialog box, that opens.
- Optionally specify the
jest.configfile to use. If the field is empty, WebStorm looks for a
package.jsonfile with a
jestkey. The search is performed in the file system upwards from the working directory. If no appropriate
package.jsonfile is found, then the Jest default configuration is used.
Launching tests via a run/debug configuration
- To launch the tests according to a run configuration, select the Jest run/debug configuration from the list on the main toolbar and click the Run button to the right of the list.
- The test server starts automatically without any steps from your side. View and analyze messages from the test server in the Run tool window.
- Monitor test execution in the Test Runner tab of the Run tool window as described in Monitoring and Managing Tests.