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 PlaywrightPageorLocatorto search withintestSubj— thedata-test-subjvalue 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
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.