Back to Storybook

Automock Register Mock File

docs/_snippets/automock-register-mock-file.md

10.3.64.5 KB
Original Source
ts
// Replace your-framework with the framework you are using (e.g., react-vite, nextjs, vue3-vite, sveltekit)
import type { Preview } from '@storybook/your-framework';
import { sb } from 'storybook/test';

// ๐Ÿ‘‡ Replaces imports of this module with imports to `../lib/__mocks__/session.ts`
sb.mock(import('../lib/session.ts'));
// ๐Ÿ‘‡ Replaces imports of this module with imports to `../__mocks__/uuid.ts`
sb.mock(import('uuid'));

const preview: Preview = {
  // ...
};

export default preview;
js
import { sb } from 'storybook/test';

// ๐Ÿ‘‡ Replaces imports of this module with imports to `../lib/__mocks__/session.ts`
sb.mock('../lib/session.js');
// ๐Ÿ‘‡ Replaces imports of this module with imports to `../__mocks__/uuid.ts`
sb.mock('uuid');

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

import { sb } from 'storybook/test';

// ๐Ÿ‘‡ Replaces imports of this module with imports to `../lib/__mocks__/session.ts`
sb.mock(import('../lib/session.ts'));
// ๐Ÿ‘‡ Replaces imports of this module with imports to `../__mocks__/uuid.ts`
sb.mock(import('uuid'));

export default definePreview({
  // ...
});
<!-- 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 { sb } from 'storybook/test';

// ๐Ÿ‘‡ Replaces imports of this module with imports to `../lib/__mocks__/session.ts`
sb.mock('../lib/session.js');
// ๐Ÿ‘‡ Replaces imports of this module with imports to `../__mocks__/uuid.ts`
sb.mock('uuid');

export default definePreview({
  // ...
});
ts
import { definePreview } from '@storybook/vue3-vite';

import { sb } from 'storybook/test';

// ๐Ÿ‘‡ Replaces imports of this module with imports to `../lib/__mocks__/session.ts`
sb.mock(import('../lib/session.ts'));
// ๐Ÿ‘‡ Replaces imports of this module with imports to `../__mocks__/uuid.ts`
sb.mock(import('uuid'));

export default definePreview({
  // ...
});
<!-- JS snippets still needed while providing both CSF 3 & Next -->
js
import { definePreview } from '@storybook/vue3-vite';

import { sb } from 'storybook/test';

// ๐Ÿ‘‡ Replaces imports of this module with imports to `../lib/__mocks__/session.ts`
sb.mock('../lib/session.js');
// ๐Ÿ‘‡ Replaces imports of this module with imports to `../__mocks__/uuid.ts`
sb.mock('uuid');

export default definePreview({
  // ...
});
ts
import { definePreview } from '@storybook/angular';

import { sb } from 'storybook/test';

// ๐Ÿ‘‡ Replaces imports of this module with imports to `../lib/__mocks__/session.ts`
sb.mock(import('../lib/session.ts'));
// ๐Ÿ‘‡ Replaces imports of this module with imports to `../__mocks__/uuid.ts`
sb.mock(import('uuid'));

export default definePreview({
  // ...
});
ts
import { definePreview } from '@storybook/web-components-vite';

import { sb } from 'storybook/test';

// ๐Ÿ‘‡ Replaces imports of this module with imports to `../lib/__mocks__/session.ts`
sb.mock(import('../lib/session.ts'));
// ๐Ÿ‘‡ Replaces imports of this module with imports to `../__mocks__/uuid.ts`
sb.mock(import('uuid'));

export default definePreview({
  // ...
});
<!-- JS snippets still needed while providing both CSF 3 & Next -->
js
import { definePreview } from '@storybook/web-components-vite';

import { sb } from 'storybook/test';

// ๐Ÿ‘‡ Replaces imports of this module with imports to `../lib/__mocks__/session.ts`
sb.mock('../lib/session.js');
// ๐Ÿ‘‡ Replaces imports of this module with imports to `../__mocks__/uuid.ts`
sb.mock('uuid');

export default definePreview({
  // ...
});