Debugging JavaScript Unit Tests
Besides simply executing unit tests on the JSTestDriver or Karma without the ability to analyze the problems that arise, PhpStorm 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 PhpStorm.
- 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
- Prepare the unit tests to run.
- In the unit tests, set the breakpoints for PhpStorm to postpone test execution at.
-
Create a JSTestDriver configuration file
*.jstd
or*.conf
. For details, see JSTestDriver Configuration file. - Start a PhpStorm 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 PhpStorm.
-
Create a Karma configuration file
karma.conf
. For details, see Running Unit Tests on 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
Last modified: 24 November 2016