Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to do Unit Tests? #5

Open
floratmin opened this issue Jan 19, 2024 · 1 comment
Open

How to do Unit Tests? #5

floratmin opened this issue Jan 19, 2024 · 1 comment

Comments

@floratmin
Copy link

floratmin commented Jan 19, 2024

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

@floratmin
Copy link
Author

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');
  });
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant