Debugging JavaScript Unit Tests
This feature is supported in the Ultimate edition only.
Besides simply executing unit tests on the JSTestDriver or Karma without the ability to analyze the problems that arise, IntelliJ IDEA provides the ability to debug unit tests just like JavaScript source code.
On this page:
Prerequisites
- The JSTestDriver or Karma test runner is installed and configured.
- Additional third-party testing frameworks, for example, Jasmine, QUnit, or Mocha, are downloaded and integrated with IntelliJ IDEA.
- A runner-specific configuration file is generated or written manually.
For more details, see Testing JavaScript with Karma or Testing JavaScript with JSTestDriver depending on your choice.
Debugging unit tests executed on JSTestDriver
- Prepare the unit tests to run.
- In the unit tests, set the breakpoints for IntelliJ IDEA to postpone test execution at.
- Create a JSTestDriver configuration file
*.jstd
or*.conf
. For details, see JSTestDriver Configuration file. - Start a IntelliJ IDEA default JSTestDriver test server.
- Capture a browser to execute the tests in.
- Create a JSTestDriver run configuration. If you have captured two browsers, specify the browser for debugging the tests: in the Debug tab of the Run/Debug Configuration: JSTestDriver dialog box, choose the relevant browser from the Debug drop-down list. The available options are Chrome and Dartium.
- Choose on the main menu, or click Debug button
on the toolbar, or press Shift+F9.
- In the Debug tool window that opens, proceed as usual: step through the program, stop and resume program execution, examine it when suspended, etc.
Debugging unit tests executed on Karma
- Prepare tests manually or have tests generated by IntelliJ IDEA.
- Create a Karma configuration file
karma.conf
. For details, see Testing JavaScript with Karma. - Create a run configuration of the type Karma.
- On the main toolbar, select the Karma run configuration in the Run/Debug Configurations drop-down list and click Debug button
on the toolbar, or press Shift+F9.
- In the Debug tool window that opens, proceed as usual: step through the program, stop and resume program execution, examine it when suspended, etc.
See Also
Procedures:
Language and Framework-Specific Guidelines:
Last modified: 18 July 2017