Skip to main content

Function: withDriver()

withDriver<D, C>(driverClass, fn, option?): (context) => Promise<void>

Defined in: storybook/src/withDriver.ts:32

Build a Storybook play function around a single driver rooted at the story's root element — the lowest-ramp path for the one-component-per-story case: no ScenePart, no locators, no canvasElement plumbing.

The returned function constructs driverClass over the story's rendered root (see WithDriverOption.locator) and passes the full play context through to fn augmented with the typed driver.

Type Parameters​

D​

D extends ComponentDriver<any>

C​

C extends StorybookPlayContext = StorybookPlayContext

Parameters​

driverClass​

ComponentDriverCtor<D>

fn​

(context) => Promise<void>

option?​

WithDriverOption

Returns​

(context) => Promise<void>

Example​

export const Increments: Story = {
play: withDriver(HTMLButtonDriver, async ({ driver }) => {
await driver.click();
}),
};