Back to Storybook

await-interactions

code/lib/eslint-plugin/docs/rules/await-interactions.md

10.3.61.7 KB
Original Source

await-interactions

<!-- RULE-CATEGORIES:START -->

Included in these configurations: <ul><li>addon-interactions</li><li>flat/addon-interactions</li><li>recommended</li><li>flat/recommended</li></ul>

<!-- RULE-CATEGORIES:END -->

Rule Details

Storybook provides an instrumented version of the testing library in the storybook/test core package (formerly available in @storybook/testing-library). When writing interactions, make sure to await them, so that addon-interactions can intercept these helper functions and allow you to step through them when debugging.

Examples of incorrect code for this rule:

js
import { userEvent, within } from "storybook/test";

// or from the legacy package "@storybook/testing-library";

MyStory.play = (context) => {
  const canvas = within(context.canvasElement);
  // not awaited!
  userEvent.click(canvas.getByRole("button"));
};

Examples of correct code for this rule:

js
import { userEvent, within } from "storybook/test";

// or from the legacy package "@storybook/testing-library";

MyStory.play = async (context) => {
  const canvas = within(context.canvasElement);
  // awaited 👍
  await userEvent.click(canvas.getByRole("button"));
};

When Not To Use It

This rule should not be applied in test files. Please ensure you are defining the Storybook rules only for story files. You can see more details here.