WebStorm 2016.3 Help

Debugging JavaScript Unit Tests

Besides simply executing unit tests on the JSTestDriver or Karma without the ability to analyze the problems that arise, WebStorm provides the ability to debug unit tests just like JavaScript source code.

On this page:

Prerequisites

  1. The JSTestDriver or Karma test runner is installed and configured.
  2. Additional third-party testing frameworks, for example, Jasmine, QUnit, or Mocha, are downloaded and integrated with WebStorm.
  3. A runner-specific configuration file is generated or written manually.

For more details, see Preparing to Use Karma Test Runner or Preparing to Use JSTestDriver Test Runner depending on your choice.

Debugging unit tests executed on JSTestDriver

  1. Prepare the unit tests to run.
  2. In the unit tests, set the breakpoints for WebStorm to postpone test execution at.
  3. Create a JSTestDriver configuration file *.jstd or *.conf. For details, see JSTestDriver Configuration file.
  4. Start a WebStorm default JSTestDriver test server.
  5. Capture a browser to execute the tests in.
  6. 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.
  7. Choose Run | Debug on the main menu, or click Debug button /help/img/idea/2016.3/debug.png on the toolbar, or press Shift+F9.
  8. 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

  1. Prepare tests manually or have tests generated by WebStorm.
  2. Create a Karma configuration file karma.conf. For details, see Running Unit Tests on Karma.
  3. Create a run configuration of the type Karma.
  4. On the main toolbar, select the Karma run configuration in the Run/Debug Configurations drop-down list and click Debug button /help/img/idea/2016.3/debug.png on the toolbar, or press Shift+F9.
  5. 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

Last modified: 22 March 2017