@elastic/eui-test-helpers is a library of test helpers to use when testing EUI components
with Cypress, React Testing Library, or Scout. It provides assertion, find, and query helpers to make interacting
with EUI components easy and reliable. Say goodbye to finding CSS selectors to query that seem right.
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.
This library's versioning is following @elastic/eui and must be kept in sync to ensure correct functionality.
yarn add --dev @elastic/eui-test-helpersFor 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/playwright';
const combo = new EuiComboBoxObject(page, 'dataViewSelector');
await combo.selectOption('logs-*');
expect(await combo.getSelectedOptions()).toContain('logs-*');The constructor's second argument is the data-test-subj set by the
consumer on the <EuiComboBox> element (the outer .euiComboBox wrapper).
@playwright/test is declared as a peerDependency β consumers provide
their own version at runtime.
- Add
data-test-subjconstants tosrc/components/<name>/selectors.ts(single source of truth β never inline test-subj strings in helpers). - Add the Component Object class in
src/components/<name>/object.ts, extendingBaseObjectand importing constants fromselectors.ts. - Add validation tests in
src/components/<name>/object.spec.tsagainst the component's Storybook story. - Re-export the new class from
src/index.ts.
The validation tests run against EUI's Storybook. Start it in a separate terminal first:
cd packages/eui
yarn build:workspaces # one-time, builds eui-theme-common + eui-theme-borealis
yarn start # starts Storybook on http://localhost:6006Wait until Storybook finishes compiling. Then, from the repository root:
yarn workspace @elastic/eui-test-helpers testThis runs tsc --noEmit (lint) followed by playwright test (the actual
tests). To run only the tests, use test-unit. On a fresh checkout you'll
also need to install Playwright's browsers once:
yarn workspace @elastic/eui-test-helpers exec playwright install chromiumAfter a failed run, open the HTML report (with traces, screenshots, and the full call log) via:
yarn workspace @elastic/eui-test-helpers show-report