docs/_snippets/shadow-dom-testing-library-in-preview.md
import type { Preview } from '@storybook/web-components-vite';
import { within as withinShadow } from 'shadow-dom-testing-library';
const preview: Preview = {
// ๐ Augment the canvas with the shadow DOM queries
beforeEach({ canvasElement, canvas }) {
Object.assign(canvas, { ...withinShadow(canvasElement) });
},
// ...
};
// ๐ Extend TypeScript types for safety
export type ShadowQueries = ReturnType<typeof withinShadow>;
// Since [email protected]
declare module 'storybook/internal/csf' {
interface Canvas extends ShadowQueries {}
}
export default preview;
import { within as withinShadow } from 'shadow-dom-testing-library';
export default {
// ๐ Augment the canvas with the shadow DOM queries
beforeEach({ canvasElement, canvas }) {
Object.assign(canvas, { ...withinShadow(canvasElement) });
},
// ...
};
import { definePreview } from '@storybook/web-components-vite';
import { within as withinShadow } from 'shadow-dom-testing-library';
// ๐ Extend TypeScript types for safety
export type ShadowQueries = ReturnType<typeof withinShadow>;
// Since [email protected]
declare module 'storybook/internal/csf' {
interface Canvas extends ShadowQueries {}
}
export default definePreview({
// ๐ Augment the canvas with the shadow DOM queries
beforeEach({ canvasElement, canvas }) {
Object.assign(canvas, { ...withinShadow(canvasElement) });
},
// ...
});
import { definePreview } from '@storybook/web-components-vite';
import { within as withinShadow } from 'shadow-dom-testing-library';
export default definePreview({
// ๐ Augment the canvas with the shadow DOM queries
beforeEach({ canvasElement, canvas }) {
Object.assign(canvas, { ...withinShadow(canvasElement) });
},
// ...
});