Back to Storybook

Msw Addon Initialize

docs/_snippets/msw-addon-initialize.md

10.3.64.4 KB
Original Source
js
import { initialize, mswLoader } from 'msw-storybook-addon';

/*
 * Initializes MSW
 * See https://github.com/mswjs/msw-storybook-addon#configuring-msw
 * to learn how to customize it
 */
initialize();

export default {
  loaders: [mswLoader], // ๐Ÿ‘ˆ Add the MSW loader to all stories
};
ts
// Replace your-framework with the framework you are using, e.g. react-vite, nextjs, vue3-vite, etc.
import type { Preview } from '@storybook/your-framework';

import { initialize, mswLoader } from 'msw-storybook-addon';

/*
 * Initializes MSW
 * See https://github.com/mswjs/msw-storybook-addon#configuring-msw
 * to learn how to customize it
 */
initialize();

const preview: Preview = {
  loaders: [mswLoader], // ๐Ÿ‘ˆ Add the MSW loader to all stories
};

export default preview;
ts
// Replace your-framework with the framework you are using (e.g., react-vite, nextjs, nextjs-vite)
import { definePreview } from '@storybook/your-framework';

import { initialize, mswLoader } from 'msw-storybook-addon';

/*
 * Initializes MSW
 * See https://github.com/mswjs/msw-storybook-addon#configuring-msw
 * to learn how to customize it
 */
initialize();

export default definePreview({
  loaders: [mswLoader], // ๐Ÿ‘ˆ Add the MSW loader to all stories
});
<!-- JS snippets still needed while providing both CSF 3 & Next -->
js
// Replace your-framework with the framework you are using (e.g., react-vite, nextjs, nextjs-vite)
import { definePreview } from '@storybook/your-framework';

import { initialize, mswLoader } from 'msw-storybook-addon';

/*
 * Initializes MSW
 * See https://github.com/mswjs/msw-storybook-addon#configuring-msw
 * to learn how to customize it
 */
initialize();

export default definePreview({
  loaders: [mswLoader], // ๐Ÿ‘ˆ Add the MSW loader to all stories
});
ts
import { definePreview } from '@storybook/vue3-vite';

import { initialize, mswLoader } from 'msw-storybook-addon';

/*
 * Initializes MSW
 * See https://github.com/mswjs/msw-storybook-addon#configuring-msw
 * to learn how to customize it
 */
initialize();

export default definePreview({
  loaders: [mswLoader], // ๐Ÿ‘ˆ Add the MSW loader to all stories
});
js
import { definePreview } from '@storybook/vue3-vite';

import { initialize, mswLoader } from 'msw-storybook-addon';

/*
 * Initializes MSW
 * See https://github.com/mswjs/msw-storybook-addon#configuring-msw
 * to learn how to customize it
 */
initialize();

export default definePreview({
  loaders: [mswLoader], // ๐Ÿ‘ˆ Add the MSW loader to all stories
});
ts
import { definePreview } from '@storybook/angular';

import { initialize, mswLoader } from 'msw-storybook-addon';

/*
 * Initializes MSW
 * See https://github.com/mswjs/msw-storybook-addon#configuring-msw
 * to learn how to customize it
 */
initialize();

export default definePreview({
  loaders: [mswLoader], // ๐Ÿ‘ˆ Add the MSW loader to all stories
});
ts
import { definePreview } from '@storybook/web-components-vite';

import { initialize, mswLoader } from 'msw-storybook-addon';

/*
 * Initializes MSW
 * See https://github.com/mswjs/msw-storybook-addon#configuring-msw
 * to learn how to customize it
 */
initialize();

export default definePreview({
  loaders: [mswLoader], // ๐Ÿ‘ˆ Add the MSW loader to all stories
});
<!-- JS snippets still needed while providing both CSF 3 & Next -->
js
import { definePreview } from '@storybook/web-components-vite';

import { initialize, mswLoader } from 'msw-storybook-addon';

/*
 * Initializes MSW
 * See https://github.com/mswjs/msw-storybook-addon#configuring-msw
 * to learn how to customize it
 */
initialize();

export default definePreview({
  loaders: [mswLoader], // ๐Ÿ‘ˆ Add the MSW loader to all stories
});