fbredius/storybook

View on GitHub
docs/snippets/common/login-form-with-play-function.js.mdx

Summary

Maintainability
Test Coverage
```js
// LoginForm.stories.jsx | LoginForm.stories.js | LoginForm.stories.ts | LoginForm.stories.tsx

import { userEvent, within } from '@storybook/testing-library';

import { LoginForm } from './LoginForm';

export default {
  component: LoginForm,
};

export const Example = {
  play: async ({ canvasElement }) => {
    // Queries the DOM and looks for the root element of the component and assigns it for a performance boost
    const canvas = within(canvasElement);
    
    await userEvent.type(canvas.getByTestId('email'), 'email@provider.com', {
      delay: 100,
    });
    await userEvent.type(canvas.getByTestId('password'), 'a-random-password'{
      delay: 100,
    });
    // See https://storybook.js.org/docs/7.0/angular/essentials/actions#automatically-matching-args to learn how to setup logging in the Actions panel
    await userEvent.click(canvas.getByRole('button'));
  },
};
```