> To build a Wix site agentically, or add Wix features like bookings or a store to a site you already have, follow https://www.wix.com/headless/skill.md
> 
> Portal Navigation:
> 
> - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version.
> - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages).
> - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`).
> - If a reference page seems to be missing its schema (parameters, return types, or type definitions), append `?schema=true` to its `.md` URL (e.g. `https://dev.wix.com/docs/contexts/contexts/stores/category-info/use-category-info-context.md?schema=true`).
> - Top-level index of all portals: https://dev.wix.com/docs/llms.txt
> - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt

## Resource: Test Drivers

## Article: Test Drivers

## Article Link: https://dev.wix.com/docs/wix-design-system/contributing/test-drivers.md

## Article Content:

<!-- heading -->

# Test Drivers

<!-- end heading -->

<br />

> If you're not familiar with what component test drivers are, start by reading [this article](invalid-url) 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](invalid-url), 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:

<!-- grid layout -->

<!-- grid layout item -->

<!-- grid layout content -->

```diff
- click()
- pressKeyDown()
- clickOption(index)

+ selectOption(index)
```

<!-- end grid layout -->

<!-- end grid layout item -->

<!-- end grid layout content -->

---

## 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:

<!-- grid layout -->

<!-- grid layout item -->

<!-- grid layout content -->

```diff
- clickClearButton()

+ clear()
```

<!-- end grid layout -->

<!-- end grid layout item -->

<!-- end grid layout content -->

- 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`.

<!-- grid layout -->

<!-- grid layout item -->

<!-- grid layout content -->

```js
<div>
  <button data-hook="confirm">{props.confirmText}</button>
</div>
```

<!-- end grid layout -->

<!-- end grid layout item -->

<!-- end grid layout content -->

- Only return elements from getters in render slots; otherwise, avoid returning elements.

<!-- grid layout -->

<!-- grid layout item -->

<!-- grid layout content -->

```js
<Button prefixIcon={<Pencil />} />
```

<!-- end grid layout -->

<!-- end grid layout item -->

<!-- end grid layout content -->

- 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:

<!-- grid layout -->

<!-- grid layout item -->

<!-- grid layout content -->

```js
import { ButtonTestkit } from '@wix/design-system/dist/testkit'; // vanilla
import { ButtonTestkit } from '@wix/design-system/dist/testkit/testing-library';
import { ButtonTestkit } from '@wix/design-system/dist/testkit/puppeteer';
import { ButtonTestkit } from '@wix/design-system/dist/testkit/enzyme';
```

<!-- end grid layout -->

<!-- end grid layout item -->

<!-- end grid layout content -->

3. The testkit must be invoked with a wrapper (DOM node for vanilla, enzyme wrapper for enzyme) and `dataHook`.

<!-- grid layout -->

<!-- grid layout item -->

<!-- grid layout content -->

```js
import { ButtonTestkit } from '@wix/design-system/dist/testkit';
const wrapper = ReactTestUtils.renderIntoDocument(<MyApp>);
const buttonDriver = ButtonTestkit({wrapper, dataHook: 'my-button'})
```

<!-- end grid layout -->

<!-- end grid layout item -->

<!-- end grid layout content -->

<br>
<br>
<br>
<br>
<br>