docs/_snippets/mount-advanced.md
// Replace your-framework with the framework you are using, e.g., react-vite, nextjs, nextjs-vite, etc.
import type { Meta, StoryObj } from '@storybook/your-framework';
// ๐ Automocked module resolves to '../lib/__mocks__/db'
import db from '../lib/db';
import { Page } from './Page';
const meta = { component: Page } satisfies Meta<typeof Page>;
export default meta;
type Story = StoryObj<typeof meta>;
export const Basic: Story = {
play: async ({ mount, args, userEvent }) => {
const note = await db.note.create({
data: { title: 'Mount inside of play' },
});
const canvas = await mount(
// ๐ Pass data that is created inside of the play function to the component
// For example, a just-generated UUID
<Page {...args} params={{ id: String(note.id) }} />,
);
await userEvent.click(await canvas.findByRole('menuitem', { name: /login to add/i }));
},
argTypes: {
// ๐ Make the params prop un-controllable, as the value is always overridden in the play function.
params: { control: { disable: true } },
},
};
// ๐ Automocked module resolves to '../lib/__mocks__/db'
import db from '../lib/db';
import { Page } from './Page';
export default { component: Page };
export const Basic = {
play: async ({ mount, args, userEvent }) => {
const note = await db.note.create({
data: { title: 'Mount inside of play' },
});
const canvas = await mount(
// ๐ Pass data that is created inside of the play function to the component
// For example, a just-generated UUID
<Page {...args} params={{ id: String(note.id) }} />,
);
await userEvent.click(await canvas.findByRole('menuitem', { name: /login to add/i }));
},
argTypes: {
// ๐ Make the params prop un-controllable, as the value is always overridden in the play function.
params: { control: { disable: true } },
},
};
import type { Meta, StoryObj } from '@storybook/angular';
// ๐ Automocked module resolves to '../lib/__mocks__/db'
import db from '../lib/db';
import { Page } from './page.component';
const meta = { component: Page } satisfies Meta<typeof Page>;
export default meta;
type Story = StoryObj<typeof meta>;
export const Basic: Story = {
play: async ({ mount, args, userEvent }) => {
const note = await db.note.create({
data: { title: 'Mount inside of play' },
});
const canvas = await mount(
Page,
// ๐ Pass data that is created inside of the play function to the component
// For example, a just-generated UUID
{ props: { ...args, params: { id: String(note.id) } } },
);
await userEvent.click(await canvas.findByRole('menuitem', { name: /login to add/i }));
},
argTypes: {
// ๐ Make the params prop un-controllable, as the value is always overridden in the play function.
params: { control: { disable: true } },
},
};
import preview from '../.storybook/preview';
// ๐ Automocked module resolves to '../lib/__mocks__/db'
import db from '../lib/db';
import { Page } from './page.component';
const meta = preview.meta({ component: Page });
export const Basic = meta.story({
play: async ({ mount, args, userEvent }) => {
const note = await db.note.create({
data: { title: 'Mount inside of play' },
});
const canvas = await mount(
Page,
// ๐ Pass data that is created inside of the play function to the component
// For example, a just-generated UUID
{ props: { ...args, params: { id: String(note.id) } } },
);
await userEvent.click(await canvas.findByRole('menuitem', { name: /login to add/i }));
},
argTypes: {
// ๐ Make the params prop un-controllable, as the value is always overridden in the play function.
params: { control: { disable: true } },
},
});
// Replace your-framework with the framework you are using, e.g., svelte-vite, sveltekit, etc.
import type { Meta, StoryObj } from '@storybook/your-framework';
// ๐ Automocked module resolves to '../lib/__mocks__/db'
import db from '../lib/db';
import Page from './Page.svelte';
const meta = { component: Page } satisfies Meta<typeof Page>;
export default meta;
type Story = StoryObj<typeof meta>;
export const Basic: Story = {
play: async ({ mount, args, userEvent }) => {
const note = await db.note.create({
data: { title: 'Mount inside of play' },
});
const canvas = await mount(
Page,
// ๐ Pass data that is created inside of the play function to the component
// For example, a just-generated UUID
{ props: { ...args, params: { id: String(note.id) } } },
);
await userEvent.click(await canvas.findByRole('menuitem', { name: /login to add/i }));
},
argTypes: {
// ๐ Make the params prop un-controllable, as the value is always overridden in the play function.
params: { control: { disable: true } },
},
};
// ๐ Automocked module resolves to '../lib/__mocks__/db'
import db from '../lib/db';
import Page from './Page.svelte';
export default { component: Page };
export const Basic = {
play: async ({ mount, args, userEvent }) => {
const note = await db.note.create({
data: { title: 'Mount inside of play' },
});
const canvas = await mount(
Page,
// ๐ Pass data that is created inside of the play function to the component
// For example, a just-generated UUID
{ props: { ...args, params: { id: String(note.id) } } },
);
await userEvent.click(await canvas.findByRole('menuitem', { name: /login to add/i }));
},
argTypes: {
// ๐ Make the params prop un-controllable, as the value is always overridden in the play function.
params: { control: { disable: true } },
},
};
import type { Meta, StoryObj } from '@storybook/vue3-vite';
// ๐ Automocked module resolves to '../lib/__mocks__/db'
import db from '../lib/db';
import Page from './Page.vue';
const meta = { component: Page } satisfies Meta<typeof Page>;
export default meta;
type Story = StoryObj<typeof meta>;
export const Basic: Story = {
play: async ({ mount, args, userEvent }) => {
const note = await db.note.create({
data: { title: 'Mount inside of play' },
});
const canvas = await mount(
Page,
// ๐ Pass data that is created inside of the play function to the component
// For example, a just-generated UUID
{ props: { ...args, params: { id: String(note.id) } } },
);
await userEvent.click(await canvas.findByRole('menuitem', { name: /login to add/i }));
},
argTypes: {
// ๐ Make the params prop un-controllable, as the value is always overridden in the play function.
params: { control: { disable: true } },
},
};
// ๐ Automocked module resolves to '../lib/__mocks__/db'
import db from '../lib/db';
import Page from './Page.vue';
export default { component: Page };
export const Basic = {
play: async ({ mount, args, userEvent }) => {
const note = await db.note.create({
data: { title: 'Mount inside of play' },
});
const canvas = await mount(
Page,
// ๐ Pass data that is created inside of the play function to the component
// For example, a just-generated UUID
{ props: { ...args, params: { id: String(note.id) } } },
);
await userEvent.click(await canvas.findByRole('menuitem', { name: /login to add/i }));
},
argTypes: {
// ๐ Make the params prop un-controllable, as the value is always overridden in the play function.
params: { control: { disable: true } },
},
};
import preview from '../.storybook/preview';
// ๐ Automocked module resolves to '../lib/__mocks__/db'
import db from '../lib/db';
import { Page } from './Page';
const meta = preview.meta({ component: Page });
export const Basic = meta.story({
play: async ({ mount, args, userEvent }) => {
const note = await db.note.create({
data: { title: 'Mount inside of play' },
});
const canvas = await mount(
// ๐ Pass data that is created inside of the play function to the component
// For example, a just-generated UUID
<Page {...args} params={{ id: String(note.id) }} />,
);
await userEvent.click(await canvas.findByRole('menuitem', { name: /login to add/i }));
},
argTypes: {
// ๐ Make the params prop un-controllable, as the value is always overridden in the play function.
params: { control: { disable: true } },
},
});
import preview from '../.storybook/preview';
// ๐ Automocked module resolves to '../lib/__mocks__/db'
import db from '../lib/db';
import { Page } from './Page';
const meta = preview.meta({
component: Page,
});
export const Basic = meta.story({
play: async ({ mount, args, userEvent }) => {
const note = await db.note.create({
data: { title: 'Mount inside of play' },
});
const canvas = await mount(
// ๐ Pass data that is created inside of the play function to the component
// For example, a just-generated UUID
<Page {...args} params={{ id: String(note.id) }} />,
);
await userEvent.click(await canvas.findByRole('menuitem', { name: /login to add/i }));
},
argTypes: {
// ๐ Make the params prop un-controllable, as the value is always overridden in the play function.
params: { control: { disable: true } },
},
});
import preview from '../.storybook/preview';
// ๐ Automocked module resolves to '../lib/__mocks__/db'
import db from '../lib/db';
import Page from './Page.vue';
const meta = preview.meta({ component: Page });
export const Basic = meta.story({
play: async ({ mount, args, userEvent }) => {
const note = await db.note.create({
data: { title: 'Mount inside of play' },
});
const canvas = await mount(
Page,
// ๐ Pass data that is created inside of the play function to the component
// For example, a just-generated UUID
{ props: { ...args, params: { id: String(note.id) } } },
);
await userEvent.click(await canvas.findByRole('menuitem', { name: /login to add/i }));
},
argTypes: {
// ๐ Make the params prop un-controllable, as the value is always overridden in the play function.
params: { control: { disable: true } },
},
});
import preview from '../.storybook/preview';
// ๐ Automocked module resolves to '../lib/__mocks__/db'
import db from '../lib/db';
import Page from './Page.vue';
const meta = preview.meta({ component: Page });
export const Basic = meta.story({
play: async ({ mount, args, userEvent }) => {
const note = await db.note.create({
data: { title: 'Mount inside of play' },
});
const canvas = await mount(
Page,
// ๐ Pass data that is created inside of the play function to the component
// For example, a just-generated UUID
{ props: { ...args, params: { id: String(note.id) } } },
);
await userEvent.click(await canvas.findByRole('menuitem', { name: /login to add/i }));
},
argTypes: {
// ๐ Make the params prop un-controllable, as the value is always overridden in the play function.
params: { control: { disable: true } },
},
});