mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-09 00:19:13 +08:00
14 KiB
14 KiB
import type { Meta, StoryObj } from '@storybook/angular';
import { fireEvent, 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 ClickExample: Story = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
// See https://storybook.js.org/docs/essentials/actions#automatically-matching-args to learn how to setup logging in the Actions panel
await userEvent.click(canvas.getByRole('button'));
},
};
export const FireEventExample: Story = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
// See https://storybook.js.org/docs/essentials/actions#automatically-matching-args to learn how to setup logging in the Actions panel
await fireEvent.click(canvas.getByTestId('data-testid'));
},
};
<script module>
import { defineMeta } from '@storybook/addon-svelte-csf';
import { fireEvent, userEvent, within } from '@storybook/test';
import MyComponent from './MyComponent.svelte';
const { Story } = defineMeta({
component: MyComponent,
});
</script>
<!--
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
-->
<Story
name="ClickExample"
play={async ({ canvasElement }) => {
const canvas = within(canvasElement);
// See https://storybook.js.org/docs/essentials/actions#automatically-matching-args to learn how to setup logging in the Actions panel
await userEvent.click(canvas.getByRole('button'));
}}
/>
<Story
name="FireEventExample"
play={async ({ canvasElement }) => {
const canvas = within(canvasElement);
// See https://storybook.js.org/docs/essentials/actions#automatically-matching-args to learn how to setup logging in the Actions panel
await fireEvent.click(canvas.getByTestId('data-testid'));
}}
/>
import { fireEvent, userEvent, within } from '@storybook/test';
import MyComponent from './MyComponent.svelte';
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 ClickExample = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
// See https://storybook.js.org/docs/essentials/actions#automatically-matching-args to learn how to setup logging in the Actions panel
await userEvent.click(canvas.getByRole('button'));
},
};
export const FireEventExample = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
// See https://storybook.js.org/docs/essentials/actions#automatically-matching-args to learn how to setup logging in the Actions panel
await fireEvent.click(canvas.getByTestId('data-testid'));
},
};
import { fireEvent, 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 ClickExample = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
// See https://storybook.js.org/docs/essentials/actions#automatically-matching-args to learn how to setup logging in the Actions panel
await userEvent.click(canvas.getByRole('button'));
},
};
export const FireEventExample = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
// See https://storybook.js.org/docs/essentials/actions#automatically-matching-args to learn how to setup logging in the Actions panel
await fireEvent.click(canvas.getByTestId('data-testid'));
},
};
<script module>
import { defineMeta } from '@storybook/addon-svelte-csf';
import { fireEvent, userEvent, within } from '@storybook/test';
import MyComponent from './MyComponent.svelte';
const { Story } = defineMeta({
component: MyComponent,
});
</script>
<!--
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
-->
<Story
name="ClickExample"
play={async ({ canvasElement }) => {
const canvas = within(canvasElement);
// See https://storybook.js.org/docs/essentials/actions#automatically-matching-args to learn how to setup logging in the Actions panel
await userEvent.click(canvas.getByRole('button'));
}}
/>
<Story
name="FireEventExample"
play={async ({ canvasElement }) => {
const canvas = within(canvasElement);
// See https://storybook.js.org/docs/essentials/actions#automatically-matching-args to learn how to setup logging in the Actions panel
await fireEvent.click(canvas.getByTestId('data-testid'));
}}
/>
import type { Meta, StoryObj } from '@storybook/svelte';
import { fireEvent, userEvent, within } from '@storybook/test';
import MyComponent from './MyComponent.svelte';
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 ClickExample: Story = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
// See https://storybook.js.org/docs/essentials/actions#automatically-matching-args to learn how to setup logging in the Actions panel
await userEvent.click(canvas.getByRole('button'));
},
};
export const FireEventExample: Story = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
// See https://storybook.js.org/docs/essentials/actions#automatically-matching-args to learn how to setup logging in the Actions panel
await fireEvent.click(canvas.getByTestId('data-testid'));
},
};
// Replace your-framework with the name of your framework
import type { Meta, StoryObj } from '@storybook/your-framework';
import { fireEvent, 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 ClickExample: Story = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
// See https://storybook.js.org/docs/essentials/actions#automatically-matching-args to learn how to setup logging in the Actions panel
await userEvent.click(canvas.getByRole('button'));
},
};
export const FireEventExample: Story = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
// See https://storybook.js.org/docs/essentials/actions#automatically-matching-args to learn how to setup logging in the Actions panel
await fireEvent.click(canvas.getByTestId('data-testid'));
},
};
<script module>
import { defineMeta } from '@storybook/addon-svelte-csf';
import { fireEvent, userEvent, within } from '@storybook/test';
import MyComponent from './MyComponent.svelte';
const { Story } = defineMeta({
component: MyComponent,
});
</script>
<!--
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
-->
<Story
name="ClickExample"
play={async ({ canvasElement }) => {
const canvas = within(canvasElement);
// See https://storybook.js.org/docs/essentials/actions#automatically-matching-args to learn how to setup logging in the Actions panel
await userEvent.click(canvas.getByRole('button'));
}}
/>
<Story
name="FireEventExample"
play={async ({ canvasElement }) => {
const canvas = within(canvasElement);
// See https://storybook.js.org/docs/essentials/actions#automatically-matching-args to learn how to setup logging in the Actions panel
await fireEvent.click(canvas.getByTestId('data-testid'));
}}
/>
import type { Meta, StoryObj } from '@storybook/svelte';
import { fireEvent, userEvent, within } from '@storybook/test';
import MyComponent from './MyComponent.svelte';
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 ClickExample: Story = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
// See https://storybook.js.org/docs/essentials/actions#automatically-matching-args to learn how to setup logging in the Actions panel
await userEvent.click(canvas.getByRole('button'));
},
};
export const FireEventExample: Story = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
// See https://storybook.js.org/docs/essentials/actions#automatically-matching-args to learn how to setup logging in the Actions panel
await fireEvent.click(canvas.getByTestId('data-testid'));
},
};
// Replace your-framework with the name of your framework
import type { Meta, StoryObj } from '@storybook/your-framework';
import { fireEvent, 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 ClickExample: Story = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
// See https://storybook.js.org/docs/essentials/actions#automatically-matching-args to learn how to setup logging in the Actions panel
await userEvent.click(canvas.getByRole('button'));
},
};
export const FireEventExample: Story = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
// See https://storybook.js.org/docs/essentials/actions#automatically-matching-args to learn how to setup logging in the Actions panel
await fireEvent.click(canvas.getByTestId('data-testid'));
},
};
import { fireEvent, 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 ClickExample = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
// See https://storybook.js.org/docs/essentials/actions#automatically-matching-args to learn how to setup logging in the Actions panel
await userEvent.click(canvas.getByRole('button'));
},
};
export const FireEventExample = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
// See https://storybook.js.org/docs/essentials/actions#automatically-matching-args to learn how to setup logging in the Actions panel
await fireEvent.click(canvas.getByTestId('data-testid'));
},
};
import type { Meta, StoryObj } from '@storybook/web-components';
import { fireEvent, 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 ClickExample: Story = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
// See https://storybook.js.org/docs/essentials/actions#automatically-matching-args to learn how to setup logging in the Actions panel
await userEvent.click(canvas.getByRole('button'));
},
};
export const FireEventExample: Story = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
// See https://storybook.js.org/docs/essentials/actions#automatically-matching-args to learn how to setup logging in the Actions panel
await fireEvent.click(canvas.getByTestId('data-testid'));
},
};