Last active
          March 3, 2023 08:28 
        
      - 
      
- 
        Save hasparus/2ff11ce679063f151b38da6375d2f887 to your computer and use it in GitHub Desktop. 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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) | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | 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