Back to Storybook

Mount Basic

docs/_snippets/mount-basic.md

10.3.64.6 KB
Original Source
js
import MockDate from 'mockdate';

// ...rest of story file

export const ChristmasUI = {
  async play({ mount }) {
    MockDate.set('2024-12-25');
    // ๐Ÿ‘‡ Render the component with the mocked date
    await mount();
    // ...rest of test
  },
};
ts
import MockDate from 'mockdate';

// ...rest of story file

export const ChristmasUI: Story = {
  async play({ mount }) {
    MockDate.set('2024-12-25');
    // ๐Ÿ‘‡ Render the component with the mocked date
    await mount();
    // ...rest of test
  },
};
ts
import MockDate from 'mockdate';

import preview from '../.storybook/preview';

import Page from './page.component';

const meta = preview.meta({
  component: Page,
});

export const ChristmasUI = meta.story({
  async play({ mount }) {
    MockDate.set('2024-12-25');
    // ๐Ÿ‘‡ Render the component with the mocked date
    await mount();
    // ...rest of test
  },
});
svelte
<script module>
  import { defineMeta } from '@storybook/addon-svelte-csf';

  import Page from './Page.svelte';

  const { Story } = defineMeta({
    component: Page,
  });
</script>

<Story
  name="ChristmasUI"
  play={async ({ mount }) {
    MockDate.set('2024-12-25');
    // ๐Ÿ‘‡ Render the component with the mocked date
    await mount();
    // ...rest of test
  }}
/>
ts
import MockDate from 'mockdate';

// ...rest of story file

export const ChristmasUI: Story = {
  async play({ mount }) {
    MockDate.set('2024-12-25');
    // ๐Ÿ‘‡ Render the component with the mocked date
    await mount();
    // ...rest of test
  },
};
svelte
<script module>
  import { defineMeta } from '@storybook/addon-svelte-csf';

  import Page from './Page.svelte';

  const { Story } = defineMeta({
    component: Page,
  });
</script>

<Story
  name="ChristmasUI"
  play={async ({ mount }) {
    MockDate.set('2024-12-25');
    // ๐Ÿ‘‡ Render the component with the mocked date
    await mount();
    // ...rest of test
  }}
/>
js
import MockDate from 'mockdate';

// ...rest of story file

export const ChristmasUI = {
  async play({ mount }) {
    MockDate.set('2024-12-25');
    // ๐Ÿ‘‡ Render the component with the mocked date
    await mount();
    // ...rest of test
  },
};
ts
import MockDate from 'mockdate';

import preview from '../.storybook/preview';

import Page from './Page';

const meta = preview.meta({
  component: Page,
});

export const ChristmasUI = meta.story({
  async play({ mount }) {
    MockDate.set('2024-12-25');
    // ๐Ÿ‘‡ Render the component with the mocked date
    await mount();
    // ...rest of test
  },
});
<!-- JS snippets still needed while providing both CSF 3 & Next -->
js
import MockDate from 'mockdate';

import preview from '../.storybook/preview';

import Page from './Page';

const meta = preview.meta({
  component: Page,
});

export const ChristmasUI = meta.story({
  async play({ mount }) {
    MockDate.set('2024-12-25');
    // ๐Ÿ‘‡ Render the component with the mocked date
    await mount();
    // ...rest of test
  },
});
ts
import MockDate from 'mockdate';

import preview from '../.storybook/preview';

import Page from './Page.vue';

const meta = preview.meta({
  component: Page,
});

export const ChristmasUI = meta.story({
  async play({ mount }) {
    MockDate.set('2024-12-25');
    // ๐Ÿ‘‡ Render the component with the mocked date
    await mount();
    // ...rest of test
  },
});
js
import MockDate from 'mockdate';

import preview from '../.storybook/preview';

import Page from './Page.vue';

const meta = preview.meta({
  component: Page,
});

export const ChristmasUI = meta.story({
  async play({ mount }) {
    MockDate.set('2024-12-25');
    // ๐Ÿ‘‡ Render the component with the mocked date
    await mount();
    // ...rest of test
  },
});