Test Drivers


If you're not familiar with what component test drivers are, start by reading this article first.

Motivation

This section will focus on the motivation and the different driver types in the library.

Drivers as an Encapsulation Utility

Having a driver helps encapsulate actions, allowing tests to focus on the "what" instead of the "how."

Exposing drivers as testkits

These drivers are confirmed as working in internal tests and can also be used by consumers to interact with the component in their tests.


Technology

Unidriver

The library's modern component drivers are written using Unidriver, which supports multiple platforms (for example, @testing-library/react, enzyme, Puppeteer, etc.).

Legacy Drivers

The library still contains legacy drivers per platform. Usually, the main driver file is implemented for JSDOM, while additional files may be needed for other platforms like enzyme.

Drivers Structure

Driver File

Every component should have a driver file named Component.uni.driver.ts.

Private driver files

A component may have a private driver to encapsulate actions not intended to be exposed as a testkit. This file is named Component.private.driver.ts. Private drivers are used for actions that must be tested but shouldn't be exposed to consumers.


Drivers APIs

Driver methods are generally separated into two types - getters and interactions.

Getters

Write a getter for (almost) every prop passed, allowing consumers to verify the component's wiring. The driver should return primitive values or nodes, not complex objects.

Primitives: string, number and boolean

Props that affect rendering values are returned in their same type:

  • title: string <=> getTitle(): string
  • disabled: boolean <=> isDisabled(): bool
  • length: number <=> getLength(): number

For props affecting lifecycle or behavior, use a function to explain the behavior:

  • initiallyOpened: boolean <=> isOpen(): boolean

Array

For arrays, expose methods to receive items and return primitive values:

  • labels: [string, string] <=> getLabelAt(index: number): string
  • items: [{id, value}, {id, value}] <=> getItemIdAt(index: number): number and getItemValueAt(index: number): string

Node

For node props (render slots), return the node itself:

  • prefixIcon: node <=> getPrefixIcon(): node

Object

Separate use cases into configurations vs. rendering values. Configurations usually aren't exposed to the consumer and may be part of the private driver.

Interactions

Function

Match function props with corresponding interactive methods:

  • onClick: function <=> click()

Abstractions

For complex interactions, abstract the actions. For example, instead of exposing all necessary methods for dropdown selection, provide a simple abstraction. For example, instead of using multiple methods to achieve a dropdown selection, expose a single method that abstracts the interaction:

Copy

Best practices

  • Actions should focus on the user's intent (the "what") rather than how they interact (click, focus, keydown, etc.). For example, instead of exposing a method to click a clear button, expose a method to clear the input:
Copy
  • Test the DOM. Assertions should focus on how props set by the consumer affect the DOM, not on React props or inner state.
  • Keep drivers flat. The returned object should be simple and flat, avoiding nesting objects or other drivers unless the component is complex and has clear logically distinct parts.
  • Use data-* HTML attributes to mark and locate elements in the DOM. Use short names for data-hook.
Copy
  • Only return elements from getters in render slots; otherwise, avoid returning elements.
Copy
  • For boolean driver methods (for example, isDisabled()), test both states (true and false).
  • Avoid importing non-JS assets (for example, stylesheets) in driver files.

Exposed Testkits

This process is automated, so no action is needed from the developer side.

  1. Each component has a <ComponentName>Testkit function exposed as a public API.
  2. They are imported through a special path that depends on the platform. For example:
Copy
  1. The testkit must be invoked with a wrapper (DOM node for vanilla, enzyme wrapper for enzyme) and dataHook.
Copy





Last updated: 15 October 2026

Did this help?