Back to Storybook

After Each In Meta

docs/_snippets/after-each-in-meta.md

10.3.67.2 KB
Original Source
ts
import type { Meta, StoryObj } from '@storybook/angular';

import { Page } from './page.component';

const meta: Meta<Page> = {
  component: Page,
  // ๐Ÿ‘‡ Runs after each story in this file
  async afterEach(context) {
    console.log(`โœ… Tested ${context.name} story`);
  },
};
export default meta;

type Story = StoryObj<Page>;

export const Basic: Story = {
  async play({ canvas }) {
    // ...
  },
};
ts
import preview from '../.storybook/preview';

import { Page } from './page.component';

const meta = preview.meta({
  component: Page,
  // ๐Ÿ‘‡ Runs after each story in this file
  async afterEach(context) {
    console.log(`โœ… Tested ${context.name} story`);
  },
});

export const Basic = meta.story({
  async play({ canvas }) {
    // ...
  },
});
svelte
<script module>
  import { defineMeta } from '@storybook/addon-svelte-csf';

  import Page from './Page.svelte';

  const { Story } = defineMeta({
    component: Page,
    // ๐Ÿ‘‡ Runs after each story in this file
    async afterEach(context) {
      console.log(`โœ… Tested ${context.name} story`);
    },
  });
</script>

<Story name="Default" play={async ({ canvas }) => {
  // ...
  }}
/>
js
import Page from './Page.svelte';

export default {
  component: Page,
  // ๐Ÿ‘‡ Runs after each story in this file
  async afterEach(context) {
    console.log(`โœ… Tested ${context.name} story`);
  },
};

export const Basic = {
  async play({ canvas }) {
    // ...
  },
};
js
import { Page } from './Page';

export default {
  component: Page,
  // ๐Ÿ‘‡ Runs after each story in this file
  async afterEach(context) {
    console.log(`โœ… Tested ${context.name} story`);
  },
};

export const Basic = {
  async play({ canvas }) {
    // ...
  },
};
svelte
<script module>
  import { defineMeta } from '@storybook/addon-svelte-csf';

  import Page from './Page.svelte';

  const { Story } = defineMeta({
    component: Page,
    // ๐Ÿ‘‡ Runs after each story in this file
    async afterEach(context) {
      console.log(`โœ… Tested ${context.name} story`);
    },
  });
</script>

<Story name="Default" play={async ({ canvas }) => {
  // ...
  }}
/>
ts
// Replace your-framework with svelte-vite or sveltekit
import type { Meta, StoryObj } from '@storybook/your-framework';

import Page from './Page.svelte';

const meta = {
  component: Page,
  // ๐Ÿ‘‡ Runs after each story in this file
  async afterEach(context) {
    console.log(`โœ… Tested ${context.name} story`);
  },
} satisfies Meta<typeof Page>;
export default meta;

type Story = StoryObj<typeof meta>;

export const Basic: Story = {
  async play({ canvas }) {
    // ...
  },
};
ts
// Replace your-framework with the framework you are using, e.g. react-vite, nextjs, vue3-vite, etc.
import type { Meta, StoryObj } from '@storybook/your-framework';

import { Page } from './Page';

const meta = {
  component: Page,
  // ๐Ÿ‘‡ Runs after each story in this file
  async afterEach(context) {
    console.log(`โœ… Tested ${context.name} story`);
  },
} satisfies Meta<typeof Page>;
export default meta;

type Story = StoryObj<typeof meta>;

export const Basic: Story = {
  async play({ canvas }) {
    // ...
  },
};
js
export default {
  component: 'my-page',
  // ๐Ÿ‘‡ Runs after each story in this file
  async afterEach(context) {
    console.log(`โœ… Tested ${context.name} story`);
  },
};

export const Basic = {
  async play({ canvas }) {
    // ...
  },
};
ts
import type { Meta, StoryObj } from '@storybook/web-components-vite';

const meta: Meta = {
  component: 'my-page',
  // ๐Ÿ‘‡ Runs after each story in this file
  async afterEach(context) {
    console.log(`โœ… Tested ${context.name} story`);
  },
};
export default meta;

type Story = StoryObj;

export const Basic: Story = {
  async play({ canvas }) {
    // ...
  },
};
js
import preview from '../.storybook/preview';

const meta = preview.meta({
  component: 'my-page',
  // ๐Ÿ‘‡ Runs after each story in this file
  async afterEach(context) {
    console.log(`โœ… Tested ${context.name} story`);
  },
});

export const Basic = meta.story({
  async play({ canvas }) {
    // ...
  },
});
ts
import preview from '../.storybook/preview';

const meta = preview.meta({
  component: 'my-page',
  // ๐Ÿ‘‡ Runs after each story in this file
  async afterEach(context) {
    console.log(`โœ… Tested ${context.name} story`);
  },
});

export const Basic = meta.story({
  async play({ canvas }) {
    // ...
  },
});
ts
import preview from '../.storybook/preview';

import { Page } from './Page';

const meta = preview.meta({
  component: Page,
  // ๐Ÿ‘‡ Runs after each story in this file
  async afterEach(context) {
    console.log(`โœ… Tested ${context.name} story`);
  },
});

export const Basic = meta.story({
  async play({ canvas }) {
    // ...
  },
});
<!-- JS snippets still needed while providing both CSF 3 & Next -->
js
import preview from '../.storybook/preview';

import { Page } from './Page';

const meta = preview.meta({
  component: Page,
  // ๐Ÿ‘‡ Runs after each story in this file
  async afterEach(context) {
    console.log(`โœ… Tested ${context.name} story`);
  },
});

export const Basic = meta.story({
  async play({ canvas }) {
    // ...
  },
});
ts
import preview from '../.storybook/preview';

import Page from './Page.vue';

const meta = preview.meta({
  component: Page,
  // ๐Ÿ‘‡ Runs after each story in this file
  async afterEach(context) {
    console.log(`โœ… Tested ${context.name} story`);
  },
});

export const Basic = meta.story({
  async play({ canvas }) {
    // ...
  },
});
<!-- JS snippets still needed while providing both CSF 3 & Next -->
js
import preview from '../.storybook/preview';

import Page from './Page.vue';

const meta = preview.meta({
  component: Page,
  // ๐Ÿ‘‡ Runs after each story in this file
  async afterEach(context) {
    console.log(`โœ… Tested ${context.name} story`);
  },
});

export const Basic = meta.story({
  async play({ canvas }) {
    // ...
  },
});