Skip to content

Instantly share code, notes, and snippets.

@hasparus
Last active March 3, 2023 08:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hasparus/2ff11ce679063f151b38da6375d2f887 to your computer and use it in GitHub Desktop.
Save hasparus/2ff11ce679063f151b38da6375d2f887 to your computer and use it in GitHub Desktop.
import { ReactRenderer, StoryObj } from '@storybook/react'
import { ComponentAnnotations } from '@storybook/types'
import { describeStories } from './tiniest-storybook-test-suites'
import * as stories from './MyComponent.stories'
describeStories(stories)
function describeStories<TProps>(
stories: { default: ComponentAnnotations<ReactRenderer, TProps> } & { [K in string]: StoryObj<TProps> },
wrapper: (element: ReactElement) => RenderResult,
) {
describe(stories.default.component?.displayName!, () => {
for (const key of Object.keys(stories)) {
if (key === 'default') continue
const { play, render } = stories[key]
if (!render || !play) continue
it(`${key} story plays out`, async () => {
const root = wrapper(render({} as any, {} as any))
await play({
...stories.default,
canvasElement: root.baseElement,
} as any)
})
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment