@elastic/eui-test-helpers

中文文档
2.4.0发布于 2026/11/17SEE LICENSE IN LICENSE.txtTypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 29万

A library of EUI test helpers for RTL, Cypress and Scout

原始使用文档
文档目录5 节
  1. Installation
  2. Playwright Component Objects
  3. Available Component Objects
  4. Selectors
  5. Contributing

EUI Test Helpers

@elastic/eui-test-helpers provides helpers for interacting with EUI components reliably in consumer tests — no more guessing at CSS selectors that only seem right. Today it ships Playwright Component Objects for Scout/Playwright consumers; Cypress and React Testing Library helpers may follow.

[!NOTE] This library is in early stages of development and is missing many useful utilities. Please contribute or open a feature request if you notice anything missing!

This library provides utilities to EUI components that are non-trivial to write tests for. Please use the built-in methods for testing simple, native-like components that are provided by your testing framework of choice.

Installation

This library is versioned independently from @elastic/eui. Because the helpers target EUI's component DOM and data-test-subjs, pick a version compatible with the @elastic/eui version you're testing against.

yarn add --dev @elastic/eui-test-helpers

Playwright Component Objects

For Playwright/Scout consumers, this package ships Component Objects — semantic wrappers around a single Playwright Locator that encapsulate user-like interactions for a specific EUI component.

import { EuiComboBoxObject } from '@elastic/eui-test-helpers';

const comboBox = new EuiComboBoxObject(page, 'dataViewSelector');
await comboBox.setSelectedOptions(['logs-*']);
expect(await comboBox.getSelectedOptions()).toEqual(['logs-*']);

Every Component Object constructor takes (scope, testSubj):

  • scope — a Playwright Page or Locator to search within
  • testSubj — the data-test-subj value you set on the component's root element in your app

@playwright/test is declared as a peerDependency — consumers provide their own version at runtime.

Available Component Objects

ComponentDocumentation
EuiComboBoxObjectsrc/components/combo_box/README.md
EuiDataGridObjectsrc/components/datagrid/README.md
EuiSuperSelectObjectsrc/components/form/super_select/README.md
EuiGlobalToastListObjectsrc/components/toast/README.md
EuiSelectableObjectsrc/components/selectable/README.md
EuiSideNavObjectsrc/components/side_nav/README.md
EuiDraggableObjectsrc/components/drag_and_drop/README.md
EuiFilterButtonObjectsrc/components/filter_button/README.md
EuiFieldSearchObjectsrc/components/form/field_search/README.md
EuiSearchBarObjectsrc/components/search_bar/README.md
EuiRangeObjectsrc/components/form/range/README.md
EuiCheckboxObjectsrc/components/form/checkbox/README.md
EuiSwitchObjectsrc/components/form/switch/README.md
EuiFieldTextObjectsrc/components/form/field_text/README.md
EuiSelectObjectsrc/components/form/select/README.md
EuiPopoverObjectsrc/components/popover/README.md
EuiFlyoutObjectsrc/components/flyout/README.md
EuiAccordionObjectsrc/components/accordion/README.md
EuiContextMenuObjectsrc/components/context_menu/README.md
EuiModalObjectsrc/components/modal/README.md
EuiTableObjectsrc/components/table/README.md
EuiTabsObjectsrc/components/tabs/README.md
EuiMarkdownEditorObjectsrc/components/markdown_editor/README.md
EuiPaginationObjectsrc/components/pagination/README.md
EuiBasicTableObjectsrc/components/basic_table/README.md
EuiCallOutObjectsrc/components/call_out/README.md
EuiCardObjectsrc/components/card/README.md
EuiButtonGroupObjectsrc/components/button/button_group/README.md
EuiColorPickerObjectsrc/components/color_picker/README.md
EuiTreeViewObjectsrc/components/tree_view/README.md
EuiToolTipObjectsrc/components/tool_tip/README.md

Selectors

Each Component Object's stable selectors are exported under one selectors object, keyed by component (selectors.comboBox, selectors.dataGrid, and so on). *_SELECTOR values are CSS class selectors, *_TEST_SUBJ values are data-test-subj names EUI sets itself.

import { selectors } from '@elastic/eui-test-helpers';

page.locator(selectors.basicTable.ROW_SELECTOR);

Prefer the Component Objects. The selectors exist for tooling, such as lint rules that flag hand-written EUI selectors in consumer tests, and for the rare scoping need an object does not cover yet.

Contributing

See CONTRIBUTING.md for design principles, directory structure, and how to add new Component Objects.

版本与发布记录

@elastic/eui-test-helpers 共发布 161 个版本,首次发布于 2026/07/02;过去 12 个月发布了 161 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
2.4.0latest2026/11/17今天
2.3.0-snapshot.1794825855066snapshot2026/11/16今天
2.3.0-snapshot.17945406011672026/11/133 天前
2.3.0-snapshot.17944866778742026/11/124 天前
2.3.0-snapshot.17944540618012026/11/124 天前
2.3.0-snapshot.17943676766812026/11/115 天前

关于 @elastic/eui-test-helpers 的常见问题

@elastic/eui-test-helpers 是什么?

A library of EUI test helpers for RTL, Cypress and Scout

如何安装 @elastic/eui-test-helpers?

在项目目录运行 npm install @elastic/eui-test-helpers,或使用 pnpm add / yarn add / bun add。

@elastic/eui-test-helpers 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@elastic/eui-test-helpers 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@elastic/eui-test-helpers 可以商用吗?

@elastic/eui-test-helpers 使用 SEE LICENSE IN LICENSE.txt 许可。许可条款写在包内的独立文件中,请阅读该文件确认可否商用。以上为概括,不构成法律意见,请以许可原文为准。

@elastic/eui-test-helpers 的下载量有多少?

根据 npm 官方下载统计,@elastic/eui-test-helpers 在 2026/10/14 – 2026/11/12 这 30 天内被下载 289,610 次,日均约 9,654 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@elastic/eui-test-helpers 还在维护吗?

最新版本 2.4.0 发布于 2026/11/17(今天);至今共发布 161 个版本,其中过去 12 个月发布了 161 个;首次发布于 2026/07/02。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。