# 测试 JavaScript

> For the complete documentation index, see [llms.txt](https://www.jetbrains.com/zh-cn/help/clion/llms.txt).

> **TL;DR**
> 必需插件:
>
>
>
> `JavaScript 和 TypeScript` ，测试框架专用插件（如适用）

使用 CLion，您可以使用 [Mocha](http://mochajs.org/)、 [Jest](https://facebook.github.io/jest/) 和 [Protractor](http://www.protractortest.org) 运行和调试 JavaScript 单元测试。

> **Tip:**
> 使用专用插件支持 [Karma](https://plugins.jetbrains.com/plugin/7287-karma) 和 [Cucumber.js](https://plugins.jetbrains.com/plugin/7418-cucumber-js) 测试框架。

您可以在树形视图中查看测试结果，并轻松从那里导航到测试源代码。 在编辑器中，测试状态会显示在测试旁边，并提供快速运行或调试的选项：

![从编辑器运行单个测试](https://resources.jetbrains.com/help/img/idea/2026.3/ws_run_test_from_editor.png)

对于 Jest 和 Mocha，您还可以在 CLion 中直接查看代码覆盖率报告。

## 导航

CLion 允许您通过   前往测试   操作（ `Ctrl+Shift+T` (Windows), `⌘ ⇧ T` (macOS), `⌘ ⇧ T` (IntelliJ IDEA Classic (macOS)), `⌃ ⇧ T` (macOS System Shortcuts), `Ctrl+Shift+T` (XWin), `Ctrl+Shift+T` (GNOME), `Ctrl+Shift+T` (KDE), `Ctrl+Shift+T` (Emacs), `Ctrl+Shift+T` (Sublime Text), `Ctrl+Shift+T` (Sublime Text (macOS)), `⌘ ⇧ T` (Xcode), `Ctrl+Shift+T` (Visual Studio), `Ctrl+Shift+T` (Visual Studio (macOS)), `Ctrl+Shift+T` (ReSharper), `Ctrl+Shift+T` (ReSharper (macOS)), `Ctrl+Shift+T` (QtCreator), `Ctrl+Shift+T` (QtCreator (macOS)), `Ctrl+Shift+T` (NetBeans), `Ctrl+Shift+T` (Eclipse), `Ctrl+Shift+T` (Eclipse (macOS)) 或  `导航 | 测试` ）快速从源代码跳转到相关的测试文件。 例如，您可以从  `auth.js`  跳转到  `auth.test.js` 。

您还可以使用   结构  视图快速浏览测试文件，该视图显示了测试和套件的名称以及此文件中定义的其他符号。

![测试的结构视图](https://resources.jetbrains.com/help/img/idea/2026.3/ws_structure_view_for_tests.png)

跳转到   结构   工具窗口，请按 `Alt+7` (Windows), `⌘ 7` (macOS), `⌘ 7` (IntelliJ IDEA Classic (macOS)), `⌘ 7` (macOS System Shortcuts), `Alt+7` (XWin), `Alt+7` (GNOME), `Alt+7` (KDE), `Alt+7` (Emacs), `Alt+7` (Sublime Text), `⌘ 7` (Sublime Text (macOS)), `⌘ 3` (Xcode), `Ctrl+Alt+F` (Visual Studio), `⌃ ⌥ F` (Visual Studio (macOS)), `Ctrl+F11` (ReSharper), `⌃ F11` (ReSharper (macOS)), `Alt+7` (QtCreator), `⌘ 7` (QtCreator (macOS)), `Ctrl+7` (NetBeans), `Alt+7` (Eclipse), `⌘ 7` (Eclipse (macOS))。 或者，按 `Ctrl+F12` (Windows), `⌘ F12` (macOS), `⌘ F12` (IntelliJ IDEA Classic (macOS)), `⌘ ⇧ 7` (macOS System Shortcuts), `Ctrl+F12` (XWin), `Ctrl+F12` (GNOME), `Ctrl+0` (KDE), `Ctrl+F12` (Emacs), `Ctrl+R` (Sublime Text), `⌘ R` (Sublime Text (macOS)), `⌃ 6` (Xcode), `Alt+\` (Visual Studio), `⌥ \` (Visual Studio (macOS)), `Ctrl+F12` (ReSharper), `⌘ F12` (ReSharper (macOS)), `Ctrl+F12` (QtCreator), `⌘ F12` (QtCreator (macOS)), `Ctrl+F12` (NetBeans), `Ctrl+F3` (Eclipse), `⌘ O` (Eclipse (macOS)) 键可以在编辑器中以弹出窗口的形式打开结构视图。

## 运行并调试测试

在开始测试 JavaScript 之前，请确保按照相应页面的说明在您的项目中安装并设置了所选的 test runner。

在测试调试会话期间，您可以 [逐步执行测试](stepping-through-the-program.html)、 [停止和恢复](null)测试执行、 [在挂起时检查测试](examining-suspended-program.html)、 [在控制台中运行 JavaScript 代码片段](interactive-debugger-console.html) 等。

Procedure: 使用 Mocha 或 Jest 快速运行或调试单个测试

* 要运行测试，请点击其旁边边距中的 ![“运行”按钮](https://resources.jetbrains.com/help/img/idea/2026.3/app-client.expui.run.run.svg)或 ![重新运行](https://resources.jetbrains.com/help/img/idea/2026.3/app.actions.rerun.svg)并从列表中选择   运行 <test_name>  。

* 要调试测试，请在必要的地方 [设置断点](using-breakpoints.html)，点击测试旁边的边距中的 ![“运行”按钮](https://resources.jetbrains.com/help/img/idea/2026.3/app-client.expui.run.run.svg) 或 ![重新运行](https://resources.jetbrains.com/help/img/idea/2026.3/app.actions.rerun.svg)，并从列表中选择   调试 <test_name>  。

![从编辑器运行和调试测试](https://resources.jetbrains.com/help/img/idea/2026.3/ws_test_run_debug_gutter.png)

Procedure: 创建运行/调试配置

1. 在 [运行/调试配置](run-debug-configurations-dialog.html)对话框（  `运行 | 编辑配置` ）中，点击 ![添加新配置](https://resources.jetbrains.com/help/img/idea/2026.3/app.expui.general.add.svg)，然后选择适当的配置类型。

2. 接受默认设置或使用自定义值填写必填字段，具体测试框架请参阅帮助。

Procedure: 使用运行/调试配置运行或调试测试

* 要运行测试，请选择所需的配置，然后点击配置列表或工具栏中的 ![“运行”按钮](https://resources.jetbrains.com/help/img/idea/2026.3/app.expui.run.run.svg)或 ![运行覆盖率](https://resources.jetbrains.com/help/img/idea/2026.3/app.general.runWithCoverage.svg)。

![运行小组件：运行测试](https://resources.jetbrains.com/help/img/idea/2026.3/ws_js_test_run_widget_run.png)

* 要调试测试，请在需要的地方 [设置断点](using-breakpoints.html)，选择所需的配置，然后在配置列表或工具栏中单击 ![调试](https://resources.jetbrains.com/help/img/idea/2026.3/app.expui.run.debug.svg)。

![运行小组件：调试测试](https://resources.jetbrains.com/help/img/idea/2026.3/ws_js_test_run_widget_debug.png)

## See also

### 流程

[配置 JavaScript 库](configuring-javascript-libraries.html)

