storybookjs / solidjs

SolidJS integration for Storybook, maintained by the community
MIT License
44 stars 2 forks source link

How to do Unit Tests? #5

Open floratmin opened 7 months ago

floratmin commented 7 months ago

I tried the equivalent function to the react library but composeStory does not render to screen.

floratmin commented 7 months ago

I figured out a basic solution:

import {describe, it, expect} from 'vitest';
import Meta, {Primary} from './Button.stories';
import {Button} from './Button.tsx';
import {render} from '@solidjs/testing-library';

describe('It should create test on stories', () => {
  it('Tests stories', async () => {
    const args = {
      ...('args' in Meta ? (Meta as unknown as {args: Record<string, any>}).args : {}),
      ...('args' in Primary ? (Primary as unknown as {args: Record<string, any>}).args : {}),
      backgroundColor: 'blue',
    };
    const renderedStory = render(() => <Button {...args} />).container;
    expect(renderedStory).toHaveTextContent('Button');
  });
});