# 测试 JavaScript

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

> **TL;DR**
> 所需插件：
>
>
>
> `JavaScript 和 TypeScript`  -  插件与 IntelliJ IDEA 捆绑在一起，并默认启用。
>
>
>
> `Framework-specific plugin` （如果适用） - 在   设置 | 插件   页面上安装插件。 该插件仅在拥有 Ultimate 订阅的 IntelliJ IDEA 中可用。

> **Note:**
> IntelliJ IDEA 仅在 Ultimate 订阅下提供完整的测试支持。 否则，仅提供测试的代码补全、语法高亮和导航。

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

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

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

## 导航

IntelliJ IDEA 允许您通过   前往测试   操作（ `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)), `Ctrl+Shift+T` (Visual Studio), `Ctrl+Shift+T` (Visual Studio (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)), `Ctrl+Alt+F` (Visual Studio), `⌃ ⌥ F` (Visual Studio (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)), `Alt+\` (Visual Studio), `⌥ \` (Visual Studio (macOS)), `Ctrl+F12` (NetBeans), `Ctrl+F3` (Eclipse), `⌘ O` (Eclipse (macOS)) 键可以在编辑器中以弹出窗口的形式打开结构视图。

## 运行并调试测试

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

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

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

* 要运行测试，请点击其旁边边距中的 ![运行按钮](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

### 过程

[测试框架](testing-frameworks.html) [配置 JavaScript 库](configuring-javascript-libraries.html)

