[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Reporting
[Expand]Report and Dashboard Server
[Expand]Dashboard
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Collapse]CodeRush
  System Requirements
  Improve Performance
 [Expand]Features by Language
 [Expand]Getting Started
 [Expand]How To
 [Expand]Coding Assistance
 [Expand]Navigation and Search Tools
 [Expand]Static Code Analysis
 [Expand]Visualization Tools
 [Expand]Code Style Assistance
  Building Assistance
  Debugging Assistance
 [Expand]Refactoring Assistance
 [Collapse]Unit Testing Assistance
   Testing Framework Configuration
   Running and Debugging Tests
   Test Execution Output
   Working with Test Sessions
   Code Coverage Calculation
   JavaScript Test Runner
   Unit Test Builder
 [Expand]Decompiling Tools
 [Expand]Configuration Options
 [Expand]Extensibility
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

JavaScript Test Runner

CodeRush for Roslyn provides the Test Runner for client-side JavaScript code. It allows you to run and debug particular unit tests using the CodeRush Test Runner GUI.

Note

To enable this feature, use the Unit Testing | JavaScript Test Runner options page.

Important

Server-side JavaScript (Node.js) tests are not currently supported. Client-side tests support is limited to tests that can be run using Karma Test Runner.

The following testing frameworks are supported:

Your unit tests should be able to access the tested code. There are several ways to reference the tested modules, and CodeRush for Roslyn supports the most common ones:

Note

JavaScript TestRuner executes tests using Karma Test Runner with the browsers specified in karma.conf.js. It uses the PhantomJS headless browser if your project does not use Karma.

This document consists of the following sections:

Expanded Requirements

JavaScript Test Runner requires Node.js to be installed on your PC - CodeRush for Roslyn uses it internally.

When installing Node.js, choose LTS or Current build and select the npm package manager.

Expanded Running Tests without Karma

This section describes how to run Jasmine Unit Tests linked to the tested code using reference directives.

  1. Create an app.js file and add the following code to it (you can use your own file with tested functions):

  2. Create a tests.js file and add the following test suite to it (you can use your own file with unit tests):

  3. Add the following line at the beginning of the tests.js file:

  4. Open your project's folder in Visual Studio:

    Note

    If your JavaScript code is in a Visual Studio Solution, you can open the Solution instead.

  5. Open the Test Runner window using the CodeRush | Windows | Test Runner menu item and the tests.js file. Wait until the tests are discovered.

  6. Once the unit tests are discovered, you can run them and analyze the results. Learn more about running tests with CodeRush Test Runner in the Running and Debugging Tests topic. If you need to debug tests, refer to the Debugging Tests section.

Expanded Running Tests with Karma

This section describes how to run Jasmine Unit Tests linked to the tested code using Karma Test Runner configuration file.

  1. Create an app.js file and add the following code to it (you can use your own file with tested functions):

  2. Create a tests.js file and add the following test suite to it (you can use your own file with unit tests):

  3. Install the required packages using npm package manager by executing the following command in your project's root:

  4. Install the framework-specific packages. For Jasmine, use the following command:

    Tip

    You can specify the packages your project requires using the package.json file. Refer to the npm documentation for more inofrmation.

  5. Create a Karma configuration file (karma.conf.js) if you do not have one. You can generate karma.conf.js automatically using the following command:

    If your existing Karma configuration file was not found, create the cr.jstest.config.json file in the project's root and add the Karma configuration file's path to this file as shown below:

  6. Open your project's folder in Visual Studio:

    Note

    If your JavaScript code is in a Visual Studio Solution, you can open the Solution instead.

  7. Open the Test Runner window using the CodeRush | Windows | Test Runner menu item and the tests.js file. Wait until the tests are discovered.

  8. Once the unit tests are discovered, you can run them and analyze the results. Learn more about running tests with CodeRush Test Runner in the Running and Debugging Tests topic. If you need to debug tests, refer to the Debugging Tests section.

Expanded Debugging Tests

To debug tests, you need to use a full-featured web browser like Google Chrome or Mozilla Firefox (only Karma-enabled projects support debugging). Follow the steps below to prepare your project for debugging:

  1. Install a Karma launcher for your browser. For example, to install the Google Chrome launcher, you should execute the following command in your project's root:

  2. Add the chosen browser to your Karma configuration file's browsers section. Refer to the corresponding Karma launcher package description on the npm website for more details.
  3. Use the Debug Test button in the Test Runner window or code editor icon's menu.

The further debugging process is similar to the Karma workflow. Go to the captured browser, click the "DEBUG" button (or open http://localhost:9876/debug.html), and use the browser's web inspector to debug your test. (You may need to refresh the debug.html page).

Expanded Gulp Support

If you need to execute a Gulp task before running tests, specify the task name in the cr.jstest.config.json file in the project's root as shown below:

Note

If your cr.jstest.config.json file already contains settings, refer to the JSON format documentation to learn how to expand the JSON object with one more key/value pair.

Is this topic helpful?​​​​​​​