mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-06 15:31:16 +08:00
4.6 KiB
4.6 KiB
import type { Meta, StoryObj } from '@storybook/your-framework';
import { userEvent, within } from '@storybook/test';
import { MyComponent } from './MyComponent.component';
const meta: Meta<MyComponent> = {
component: MyComponent,
};
export default meta;
type Story = StoryObj<MyComponent>;
/*
* See https://storybook.js.org/docs/writing-stories/play-function#working-with-the-canvas
* to learn more about using the canvasElement to query the DOM
*/
export const AsyncExample: Story = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
// Other steps
// Waits for the component to be rendered before querying the element
await canvas.findByRole('button', { name: / button label/i });
},
};
import { userEvent, within } from '@storybook/test';
import { MyComponent } from './MyComponent';
export default {
component: MyComponent,
};
/* See https://storybook.js.org/docs/writing-stories/play-function#working-with-the-canvas
* to learn more about using the canvasElement to query the DOM
*/
export const AsyncExample = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
// Other steps
// Waits for the component to be rendered before querying the element
await canvas.findByRole('button', { name: / button label/i }));
},
};
// Replace your-framework with the name of your framework
import type { Meta, StoryObj } from '@storybook/your-framework';
import { userEvent, within } from '@storybook/test';
import { MyComponent } from './MyComponent';
const meta = {
component: MyComponent,
} satisfies Meta<typeof MyComponent>;
export default meta;
type Story = StoryObj<typeof meta>;
/* See https://storybook.js.org/docs/writing-stories/play-function#working-with-the-canvas
* to learn more about using the canvasElement to query the DOM
*/
export const AsyncExample: Story = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
// Other steps
// Waits for the component to be rendered before querying the element
await canvas.findByRole('button', { name: / button label/i });
},
};
// Replace your-framework with the name of your framework
import type { Meta, StoryObj } from '@storybook/your-framework';
import { userEvent, within } from '@storybook/test';
import { MyComponent } from './MyComponent';
const meta: Meta<typeof MyComponent> = {
component: MyComponent,
};
export default meta;
type Story = StoryObj<typeof MyComponent>;
/* See https://storybook.js.org/docs/writing-stories/play-function#working-with-the-canvas
* to learn more about using the canvasElement to query the DOM
*/
export const AsyncExample: Story = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
// Other steps
// Waits for the component to be rendered before querying the element
await canvas.findByRole('button', { name: / button label/i });
},
};
import { userEvent, within } from '@storybook/test';
export default {
component: 'demo-my-component',
};
/* See https://storybook.js.org/docs/writing-stories/play-function#working-with-the-canvas
* to learn more about using the canvasElement to query the DOM
*/
export const AsyncExample = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
// Other steps
// Waits for the component to be rendered before querying the element
await canvas.findByRole('button', { name: / button label/i }));
},
};
import type { Meta, StoryObj } from '@storybook/web-components';
import { userEvent, within } from '@storybook/test';
const meta: Meta = {
component: 'demo-my-component',
};
export default meta;
type Story = StoryObj;
/* See https://storybook.js.org/docs/writing-stories/play-function#working-with-the-canvas
* to learn more about using the canvasElement to query the DOM
*/
export const AsyncExample: Story = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
// Other steps
// Waits for the component to be rendered before querying the element
await canvas.findByRole('button', { name: / button label/i });
},
};